我有一個類,我需要驗證一些用戶輸入並根據輸入輸出不同的結果。非常基本的東西,但我是C品牌的新手,所以這就是我開始的地方。我以爲我是在正確的軌道上,但無論什麼整數I輸入,終端打印Good job!
這裏是我的代碼:C條件語句中的不需要的輸出
C現在
printf("How tall should the pyramid be?\n");
int n = GetInt();
if (3 <= n < 23)
{
printf("Good job!\n");
}
else if (0 < n <= 3)
{
printf("Well, that's not very impressive is it?\n");
}
else
{
printf("Please enter a valid number between 1 and 23.\n");
}
,我使用C零經驗,但我知道一些Python如果我是翻譯上面的代碼,它按預期工作:
的Python
n = input("Enter Number")
if (3 <= n < 23):
print("Good job!\n")
elif (0 < n <= 3):
print("Well, that's not very impressive is it?\n")
else:
print("Please enter a valid number between 1 and 23.\n")
爲什麼這個結構在Python中工作而不是C?我應該改變什麼,以便我的C代碼能打印正確的字符串?
@JonathanLeffler我可以看到這個已經成爲常見的問題,你的觀點是什麼。對於重複的道歉,我在搜索中太模糊了。 –
這將是很難搜索的... –