简体   繁体   English

如果 user_num2 大于 8,则为 user_num2 分配 5。打印“user_num2 小于或等于 8。”

[英]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.

相关问题 从num_dict返回值大于或等于min_cutoff的所有键(按设置) - Return all the keys (as set) from num_dict that have value greater than or equal to min_cutoff python在列表中找到大于左和右的数字 - python find the num in list greater than left and right key=lambda (user_id, num_friends): num_friends - key=lambda (user_id, num_friends): num_friends 给定面数和用户的骰子数量,同时掷出多个骰子 - Roll multiple dice at same time given num of sides and num of dice from the user 编写程序将 user_num 除以 x 3 - Writing a program to divide user_num by x 3 times 每当页码为1时,num_pages总是为1,而页码大于1时,它将正常工作 - whenever the page number is 1,the num_pages always gets 1,when the page number greater than 1,it works fine 编写一个程序,使用整数 user_num 和 x 作为输入,并将 output user_num 除以 x 三次 - Write a program using integers user_num and x as input, and output user_num divided by x three times XGBoostError:参数 num_class 的值 0 应大于等于 1 - XGBoostError: value 0 for Parameter num_class should be greater equal to 1 TensorFlow 2.6:num_parallel_calls 大于 1 但大部分时间只使用一个 CPU 内核 - TensorFlow 2.6: num_parallel_calls is greater than 1 but only one CPU core is used most of the time Python num =循环中的num +1 - Python num = num +1 in loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM