Python 应用“原始输入”时如何使用“如果”?
一般来说,我对Python和编码有些陌生,我需要一些关于Python 应用“原始输入”时如何使用“如果”?,python,Python,一般来说,我对Python和编码有些陌生,我需要一些关于raw_输入和if语句的帮助。我的代码如下 age = raw_input ("How old are you? ") if int(raw_input) < 14: print "oh yuck" if int(raw_input) > 14: print "Good, you comprehend things, lets proceed" age=raw\u输入(“你多大了?”)
raw_输入
和if
语句的帮助。我的代码如下
age = raw_input ("How old are you? ")
if int(raw_input) < 14:
print "oh yuck"
if int(raw_input) > 14:
print "Good, you comprehend things, lets proceed"
age=raw\u输入(“你多大了?”)
如果int(原始输入)<14:
打印“哦,恶心”
如果int(原始输入)>14:
打印“好,你理解了事情,让我们继续”
然后你可以做如果年龄>14,等等,因为它已经是一个整数了
我假设缩进问题(每个if
后面的行应该缩进至少一个空格,最好是四个空格)只是一个格式问题。问题
您的代码有三个问题:
- Python使用缩进创建块李>
- 您已将输入分配给变量
age
,因此请使用age
- 在Python3中,必须使用
print(…)
而不是print…
正确的解决方案
Python学习手册
- -逐步介绍编程/Python的教程
- -查找事物并发现新事物,例如。G及
if int(raw_input) < 14:
age = int(raw_input("How old are you? "))
age = raw_input("How old are you? ")
if int(age) < 14:
print("oh yuck")
else:
print("Good, you comprehend things, lets proceed")
age = int(raw_input("How old are you? "))
if age < 14:
print("oh yuck")
elif age > 14:
print("Good, you comprehend things, lets proceed")