python入門-用戶輸入


1 input()函數來實現用戶輸入,程序在等待輸入的時候會終止,獲取用戶的輸入后繼續

message = input("tell me something,and I will repreat it back to you:")
print(message)

 

2 使用int來獲取數值輸入

age = input("How old are you?")

age = int(age)

print(age)

 

3 求模運算符

number = input("Enter a number,and i'll tell you if it's even or odd:")
number = int(number)

if number % 2 == 0:
    print("\n the number" + str(number) + "is even.")
else:
    print("\n the number" + str(number) + "is odd.")

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM