[英]Assign user_num2 with 5 if user_num2 is greater than 8. print "user_num2 is less than or equal to 8."
Task: Print "user_num1 is negative."任务:打印“user_num1 是负数。” if user_num1 is less than 0. End with newline.
如果 user_num1 小于 0。以换行符结束。 Assign user_num2 with 5 if user_num2 is greater than 8. Otherwise, print "user_num2 is less than or equal to 8.".
如果 user_num2 大于 8,则将 user_num2 赋值为 5。否则,打印“user_num2 小于或等于 8”。 End with newline.
以换行结束。
Problem: I've attached my code and for some reason when user_num2 = 8 it does not output the print statement as depicted in the output image.问题:我附上了我的代码,出于某种原因,当 user_num2 = 8 时,它不会 output 打印语句,如 output 图像中所示。 What am I doing wrong?
我究竟做错了什么?
Attempted code:尝试的代码:
user_num1 = int(input())
user_num2 = int(input())
if user_num1 < 0:
print('user_num1 is negative.')
elif user_num2 <= 8:
print('user_num2 is less than or equal to 8.')
else:
user_num2 = 5
print('user_num2 is', user_num2)
Each user gets its own "if" statements.每个用户都有自己的“if”语句。 Try this out:
试试这个:
user_num1 = int(input())
user_num2 = int(input())
if user_num1 < 0:
print('user_num1 is negative.')
if user_num2 > 8:
user_num2 = 5
else:
print('user_num2 is less than or equal to 8.')
print('user_num2 is', user_num2)
This is what I understand from the text: user_num1 and user_num2 tests are independant, so each has its own "if" statement.这就是我从文本中了解到的: user_num1 和 user_num2 测试是独立的,所以每个都有自己的“if”语句。 Otherwise the user_num2 test is not executed when user_num1 < 0.
否则当 user_num1 < 0 时不会执行 user_num2 测试。
user_num1 = int(input())
user_num2 = int(input())
if user_num1 < 0:
print('user_num1 is negative.')
if user_num2 <= 8:
print('user_num2 is less than or equal to 8.')
else:
user_num2 = 5
print('user_num2 is', user_num2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.