death_age = 80
name = input(「your name」)
age = input(「your age:」) #input
注:接受的所有資料都是字串,即便你輸入的是數字,但依然會被當成字串來處理
print(type (age))
#int integer = 整數 把字串轉成int,用int(被轉的資料)
#str string =字串 把資料轉成字串用str(被轉的資料)
print(「your name:」,name)
#print("you can still live for ",death_age - int(age),「years …」)
print("you can still live for " + str(deach_age - int(age)) +「years …」)
death_age=
80 name =
input
("your name:"
)age =
input
("your age:"
)print
(type
(age)
)print
("your name:"
,name)
print
("you can still live for"
,death_age-
int(age)
,"years ...."
)print
("you can still live for"
+str
(death_age-
int(age))+
"years ...."
)
if語句實現猜年齡
age_of_princal =
56guess_age =
int(
input
(">>:"))
if guess_age == age_of_princal:
print
("yes,you got it.."
)else
:print
("no,it's wrong"
)
表示式if …else語句
縮排 indentationerror:expected an indented block
indentationerror:unindent does not match
any outer indentation level syntaxerror:invalid
syntax 語法錯誤
age_of_princal =
56guess_age =
int(
input
(">>:"))
if guess_age == age_of_princal:
print
("yes,you got it.."
)print
("yes,you got it.."
)print
("yes,you got it.."
)print
("yes,you got it.."
)else
:print
("no,it's wrong."
)
多分支if語句
1.if判斷語句
age_of_princal =
56guess_age =
int(
input
(">>:"))
if guess_age == age_of_princal:
print
("yes,you got it.."
)elif guess_age > age_of_princal:
print
("shoud try samller.."
)else
:print
("try bigger ... "
)
if猜成績語句
score =
int(
input
("score:"))
if score >90:
print
("a"
)elif score >80:
print
("b"
)elif score >70:
print
("c"
)elif score >50:
print
("d"
)else
:print
("滾"
)
python(分支語句if)(輸入輸出)的練習
1.輸入年 月,輸出本月有多少天。合理選擇分支語句完成設計任務。輸入樣例1 2004 2 輸出結果1 本月29天 輸入樣例2 2010 4 輸出結果2 本月30天 year int input 請輸入年份 month int input 請輸入月份 if year 4 0 and year 100 ...
多分支語句與格式化輸出
多分支語句 語法 if 判斷條件1 語句塊1 elif 判斷條件2 語句塊2 elif 判斷條件3 語句塊3 else 語句塊n 執行過程 首先執行判斷條件1,若條件1成立則執行語句塊1,語句塊1執行完畢則跳出 分支語句.若條件1不成立,則執行判斷條件2,若條件2成立,則執行語句塊2.若條件2不成立...
C語言輸入輸出語句
一 控制台輸入輸出 1 字元資料的輸入 輸出 字元輸出putchar int c 字元輸入getchar void 2 格式化輸入 輸出 格式輸出printf 格式控制字串 輸出列表 格式輸入scanf 格式控制字串 位址列表 3 字串的輸入 輸出 字串輸出puts const char str 字...