與小卡特一起學python 第7章 判斷再判斷 7-1-2-3-6-7
#7.1使用比較運算子
num1 = float(input ("Enter the first number:"))
num2 = float(input ("Enter the second number:"))
if num1 < num2:
print(num1,"is less than",num2)
if num1 > num2:
print(num1,"is greater than",num2)
if num1 == num2:
print(num1,"is equal to",num2)
if num1 != num2:
print(num1,"is not equal to",num2)
#7.2
answer = float(input("Enter a number from 1 to 15"))
if answer >= 10:
print("You got at least 10!")
elif answer >= 5:
print("You got at least 5!")
elif answer >=3:
print("You got at least 3")
else:
print("You got less than 3.")
#7.6測試多個條件
age = float(input("Enter your age:"))
grade = int(input("Enter your grade:"))
if age > 8:
if grade >= 3:
print("You can play this game!")
else:
print("Sorry.You can't play the game!)
#7.7 使用and,or
age = float(input("Enter your age:"))
grade = int(input("Enter your grade:"))
color = input("Enter your favorite color:")
##if age > 8 and grade >=3 and color == "green":
## print("You can play this game!")
##else:
## print("Sorry,you can't play the game!")
if color == "red" or color == "bule" or color == "green":
print("You are allowed to play this game!")
else:
print("Sorry,you can't play the game")
num1 = float(input ("Enter the first number:"))
num2 = float(input ("Enter the second number:"))
if num1 < num2:
print(num1,"is less than",num2)
if num1 > num2:
print(num1,"is greater than",num2)
if num1 == num2:
print(num1,"is equal to",num2)
if num1 != num2:
print(num1,"is not equal to",num2)
#7.2
answer = float(input("Enter a number from 1 to 15"))
if answer >= 10:
print("You got at least 10!")
elif answer >= 5:
print("You got at least 5!")
elif answer >=3:
print("You got at least 3")
else:
print("You got less than 3.")
#7.6測試多個條件
age = float(input("Enter your age:"))
grade = int(input("Enter your grade:"))
if age > 8:
if grade >= 3:
print("You can play this game!")
else:
print("Sorry.You can't play the game!)
#7.7 使用and,or
age = float(input("Enter your age:"))
grade = int(input("Enter your grade:"))
color = input("Enter your favorite color:")
##if age > 8 and grade >=3 and color == "green":
## print("You can play this game!")
##else:
## print("Sorry,you can't play the game!")
if color == "red" or color == "bule" or color == "green":
print("You are allowed to play this game!")
else:
print("Sorry,you can't play the game")
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/220205/viewspace-2073853/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 判斷存在與否
- Python判斷海域有多少個小島Python
- python條件判斷與迴圈Python
- Python判斷閏年Python
- 怎麼判斷dns汙染,怎麼判斷dns汙染,具體判斷方法DNS
- JS的判斷語句:判斷、迴圈JS
- 字元判斷字元
- 小白學python系列-(6) 條件判斷Python
- python學習-判斷閏年指令碼Python指令碼
- python學習----判斷是否是閏年Python
- js函式中的if判斷和a==b判斷JS函式
- 使用帶型別判斷的比較判斷型別
- python如何判斷字串相等Python字串
- python判斷是否為listPython
- python if判斷的使用格式Python
- Python中None如何判斷PythonNone
- python如何判斷迴文Python
- python 判斷是否為中文Python
- python中字串格式判斷Python字串
- python之判斷語句Python
- JavaScript判斷整數或者小數JavaScript
- 下拉選項,一個小判斷
- 與小卡特一起學python 第14章 物件Python物件
- js資料型別判斷和陣列判斷JS資料型別陣列
- 原型判斷方法原型
- nginx 多if判斷。Nginx
- 判斷 iOS 版本iOS
- sqlldr增加判斷。SQL
- 判斷語句
- PbootCMS判斷導航從第幾個開始各種條件判斷和標籤boot
- Python 基礎 - if else流程判斷Python
- Python中型別最佳判斷方法Python型別
- python怎麼判斷星期幾Python
- python怎麼判斷大小寫Python
- 如何使用Python判斷奇偶數?Python
- python 判斷檔案是否存在Python
- python3.0 -條件判斷Python
- python判斷list是否為空Python