如果在python中麻烦 [英] Trouble with if in python

查看:138
本文介绍了如果在python中麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿刚刚开始学习python并且已经遇到了一些问题
我用if语句创建了一个代码它应该工作但它不起作用
可以有人修复它并告诉我我做错了什么?

Hey just starting to learn python and got some problems already I made a code with an if statement It should work but it isn't working can someone fix it and tell me what I did wrong?

x= raw_input("Enter your name: ")
y= raw_input("Enter your grade: ")
print(y)
if y>=50 and y<=100:
    print("Good input")
else:
     print ("Invaild input")

它始终打印无效输入
谢谢!

It always prints Invalid input thanks!

推荐答案

raw_input()返回一个字符串但你要比较 x y 包含整数。

raw_input() returns a string but you are comparing x and y with integers.

y 比较之前输入一个整数:

Turn y into a integer before comparing:

y = int(y)
if y >= 50 and y <= 100:

您可以通过链接简化比较,让您内联 int() call:

You can simplify your comparison a little with chaining, letting you inline the int() call:

if 50 <= int(y) <= 100:

这篇关于如果在python中麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆