【发布时间】:2018-08-26 16:18:58
【问题描述】:
定义挑战(): Name = input('您好,请输入您的姓名?:') 而真: choice = input('Hi '+Name+' 有 30 个挑战需要复核 请在 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 之间输入您的选择:') 如果选择 == '1': user_age = int(input('你多大了?:')) print ('你是',user_age,'岁')
elif choice == '2':
user_num1 = int(input('Hi '+Name+' please enter your first number: '))
user_num2 = int(input('Please enter your second number: '))
total = user_num1+user_num2
average = total/2
print (average)
elif choice == '3':
width = int(input('Please enter your width: '))
height = int(input('Please enter your height: '))
area = width*height
print ('the area of your rectangle is',area,'cm')
elif choice == '4':
user_num3= int(input(+Name+' please enter a number: '))
user_num4= int(input('Now enter a second number: '))
div= user_num3/user_num4
print(div)
elif choice == '5':
Name = input('Hello Please enter your name?: ')
user_fav_sub = input('What is your favourite subject?: ')
print ('OMG '+user_fav_sub+' is my favourite aswell')
elif choice == '6':
Name = input ('Hello what is your name?: ')
if Name =='Zak':
print ('You\'re cool')
else:
print ('Nice to meet you')
elif choice == '7':
user_tv = input ('Hi '+Name+' how long do you spend watching TV?: ')
if user_tv <= '2':
print ('That shouldn\'t rit your brain too much')
elif user_tv<='4':
print ('Aren\'t you getting square eyes')
else:
print ('Fresh air beats channel flicking')
elif choice == '8':
user_mark = int(input('Hi '+Name+' how many marks did you get on your test?: '))
这就是问题所在
if user_mark < '35':
print ('You got a grade D')
elif user_mark>='35':
print ('You got a grade C')
elif user_mark>='60':
print ('You got a grade B')
else:
print('You got an A')
else:
print('Sorry incorect input please try again')
【问题讨论】:
-
user_mark 它是字符串,检查相等性,首先转换这些数字。
-
我们无法将整数与字符串进行比较 -
user_mark < '35' -
请使用编辑器格式化您的问题,全部作为代码。由于缩进在 Python 中至关重要,因此请确保您的问题准确地显示了您运行的代码。
标签: python python-3.x typeerror