[英]python if statements. and comparison operators
如何制作一個使變量小於或等於 4 且大於 1 的 if 語句
我試過 <= 4 或 >1: 但它給了我一個語法錯誤,對於 <= 4 和 >=1:
我原以為如果 if 語句不小於或等於 4 且大於 1,它就不會執行
代碼
if bitches > 1:
print("Haram")
print("Astagfirullah")
if bitches < 1:
print("Halal")
print("Mashallah")
wives = int(input("How many wives do you have? "))
if wives < 1:
print("What a faliure no wife no life")
print("OUT OF MY HOUSE!")
if wives <= 4:
print("Mashallah")
print("Halal Brother")
if wives >= 5:
print("Astagfirullah")
print("ONLY 4 WIVES GET OUT OF MY HOME")```
basically, this is the code I was playing around with if statements, and then for the part where it says
```if wives <= 4:
print("Mashallah")
print("Halal Brother")```
I wanna make it where it'll wait to verify that the value of wives is less than or equal to 4 AND greater than the value of 1
像這樣使用
import os
d = 3
if (d <= 4) and (d >= 1):
print("yes")
好的,基本上問題是 if 語句構造正確,但不是我想要的方式,但是當我將它移動到 if 1 <= x <= 4 時:感謝 John。 G,小於或等於4,大於1,它運行並執行,這次沒有語法錯誤,
if 1 <= wives <= 4:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.