日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中如何獲取用戶輸入

整數(shù)輸入

創(chuàng)新互聯(lián)是網(wǎng)站建設專家,致力于互聯(lián)網(wǎng)品牌建設與網(wǎng)絡營銷,專業(yè)領域包括成都網(wǎng)站制作、做網(wǎng)站、電商網(wǎng)站制作開發(fā)、微信小程序定制開發(fā)、微信營銷、系統(tǒng)平臺開發(fā),與其他網(wǎng)站設計及系統(tǒng)開發(fā)公司不同,我們的整合解決方案結合了恒基網(wǎng)絡品牌建設經(jīng)驗和互聯(lián)網(wǎng)整合營銷的理念,并將策略和執(zhí)行緊密結合,且不斷評估并優(yōu)化我們的方案,為客戶提供全方位的互聯(lián)網(wǎng)品牌整合方案!

#!/usr/bin/python3
usr_ip = input("Enter an integer number: ")

# 需要將輸入的字符串顯式地指定為需要的類型

usr_num = int(usr_ip)
sqr_num = usr_num * usr_num
print("Square of entered number is: {}".format(sqr_num))

讓我們給定一個整數(shù)和字符串來測定這個程序

Python docs - 整數(shù)文本

$ ./user_input_int.py
Enter an integer number: 23
Square of entered number is: 529
$ ./user_input_int.py
Enter an integer number: abc
Traceback (most recent call last):
  File "./user_input_int.py", line 6, in 
    usr_num = int(usr_ip)
ValueError: invalid literal for int() with base 10: 'abc'

浮點數(shù)輸入

#!/usr/bin/python3
usr_ip = input("Enter a floating point number: ")
# 需要將輸入的字符串顯式地指定為我們需要的類型
usr_num = float(usr_ip)
sqr_num = usr_num * usr_num
# 限制小數(shù)點位數(shù)
print("Square of entered number is: {0:.2f}".format(sqr_num))

E 科學計數(shù)法在需要時可以使用

Python文檔 - 浮點數(shù)文本

Python文檔 - 浮點數(shù)

$ ./user_input_float.py
Enter a floating point number: 3.232
Square of entered number is: 10.45
$ ./user_input_float.py
Enter a floating point number: 42.7e5
Square of entered number is: 18232900000000.00
$ ./user_input_float.py
Enter a floating point number: abc
Traceback (most recent call last):
  File "./user_input_float.py", line 6, in 
    usr_num = float(usr_ip)
ValueError: could not convert string to float: 'abc'

字符串輸入

#!/usr/bin/python3
usr_name  = input("Hi there! What's your name? ")
usr_color = input("And your favorite color is? ")
print("{}, I like the {} color too".format(usr_name, usr_color))

不像Perl,字符串輸入不需要進行類型轉換和注意換行符

$ ./user_input_str.py
Hi there! What's your name? learnbyexample
And your favorite color is? blue
learnbyexample, I like the blue color too

網(wǎng)站名稱:創(chuàng)新互聯(lián)Python教程:python中如何獲取用戶輸入
URL標題:http://m.5511xx.com/article/dpegppo.html