簡體   English   中英

我如何使這個好或壞的 python 代碼工作?

[英]How do i make this good or bad python code work?

如何使這個好的或壞的 python 代碼工作? 下面是我的代碼:

print("how are you today")

good = 1
bad = 2

if "1":
    print("thats good to hear")

if "2":
    print("thats not good")

您沒有接受用戶的輸入。 你只是在打印你今天好嗎。 讓用戶告訴他/她怎么樣。 然后使用 if 條件,根據輸入打印你的 msg。 你的代碼:

x=input("How are you today")
if x=="1":
    print("That's good to hear")
else:
    print("That's not good")

python 中的兩個襯里:)

x = input("How are you today")
print("That's good to hear") if int(x) == 1 else print("That's not good")

這只是在一行中編寫if else邏輯的 Pythonic 方式。 代碼將檢查輸入是否為1 ,然后它將執行第一個打印,即,很高興聽到。 如果輸入不等於 1,則 else 部分將運行並打印

第 1 行:您從用戶那里獲取輸入並將其設為 integer

第 2 行: myFunc 是 function ,它根據您的輸入決定 output (基本上是邏輯)

第 3 行:打印 output

input = int(input("Your number : "))
myFunc = lambda x: "That is Good" if x == 1 else "That is not good"
print(myFunc(input))
print("how are you today")
enter = int(input("enter '1' for God, and enter '2' for bad:- "))
    
good = 1 
bad = 2
    
if 1 == enter:
    print("thats good to hear")
    
if 2 == enter: 
    print("thats not good")

lmao 謝謝大家,我是愚蠢的 lmfao。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM