General Question

Corille's avatar

Can you help fix this programming problem in Python?

Asked by Corille (1points) May 20th, 2019

name = ”...”
school = ”...”
student = “Monday, 20/5/2019”
studentdetails = name + student + school
print(studentdetails)

teacherdaetails = {“teacherName”:“suh”,“teacheremail”:“suh@gmail.com”}
print(teacherdaetails)

print(”=”*50)

mass = []
print(“Enter the mass value”)
num = “0”

while num.isdigit():
num = input(“enter the mass value”)
if num.isdigit():
m = float(num)
mass.append(m)

print(mass)
acceleration=[]
print(“enter the acceleration values”)
num = “0”

while num.isdigit():
num = input(“enter acceleration value”)
if num.isdigit():
a=float(num)
acceleration.append(a)

print(acceleration)

print(max(mass))
print(min(acceleration))

Force = (“mass”[2]*“acceleration”[3])
print(Force)

print(”=”*50)

Traceback (most recent call last):
File “C:/Users/s118630/PycharmProjects/untitled/venv/Test 2.py”, line 38, in <module>
Force = (“mass”[2]*“acceleration”[3])
TypeError: can’t multiply sequence by non-int of type ‘str’

Observing members: 0 Composing members: 0

3 Answers

LostInParadise's avatar

You can’t treat arrays of digits as a single number. The easiest way to read a numeric string is to use the sys library to read a line from the keyboard.

import sys
print(“Enter value for mass”)
mass = sys.stdin.readline()
mass = float(mass)

LostInParadise's avatar

If you really want to read one digit at a time, you can use a string variable in place of an array.

mass= ””
num=“0”
while num.isdigit():
...mass += num
...num= input(“Enter mass value”)

mass=float(mass)

Response moderated (Spam)

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther