I'm new to python and trying to create a program to calculate grade. I've been stuck on below for over an hour now so any help appreciate.
assessment=[]
weight=[]
assign_number = int(input('How many assessment : '))
for i in range(assign_number):
asses_name =input('Enter name of assessment: ')
assessment.append(asses_name)
asses_value = int(input(print('How many marks is the',assessment[i],'worth : ')))
weight.append(asses_value)
the problem is the asses_value keep returning none?example is below
How many assessment : 3
Enter name of assessment: test
How many marks is the test worth :
None
Any hint is appreciated, thanks everyone
2 Answers 2
The print() function in Python always returns None. So you need to remove it from this line:
asses_value = int(input(print('How many marks is the',assessment[i],'worth : ')))
Simply passing a string to the input function does what you need:
asses_value = int(input('How many marks is the ' + assessment[i] + ' worth : '))
Note that you can only pass a single string to input() though, which is why I have used the string concatenation operator + rather than passing three comma-separated strings.
As pointed out in the comments, an improvement to the above would be to use string formatting:
asses_value = int(input('How many marks is the {} worth : '.format(assessment[i])))
Comments
Hope! This code will help you out
assessment=[]
weight=[]
assign_number = int(input('How many assessment : '))
for i in range(assign_number):
asses_name =input('Enter name of assessment: ')
assessment.append(asses_name)
asses_value = int(input('How many marks is the ' +assessment[i]+' worth : '))
weight.append(asses_value)
Update: You tried to print the the value while taking the input that's why all the error occur