日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

for循环false 终止 python_python3.5.1给用户3次无效的尝试,然后终止pgm(Simple FOR循环)...

發布時間:2025/3/8 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 for循环false 终止 python_python3.5.1给用户3次无效的尝试,然后终止pgm(Simple FOR循环)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我需要幫助(新生-2周)。我想得到這段代碼可能的最微小的變化,允許用戶3次在程序中輸入錯誤的值。輸入錯誤值3次后,程序應終止。唯一的要求是代碼必須包含FOR循環。我不知道它是需要一個FOR循環還是3個FOR循環(每次轉換一個)。我嘗試了很多種方案,但似乎都沒能把它做好。

謝謝您!!!!在miles = float(input('Type miles to be converted to km.\n'))

if miles >= 0:

milesToKm = miles * 1.6

print (miles, 'miles is', format(milesToKm, ',.1f'), 'kilometers.\n')

inch = float(input('Give me inches to convert to cm.\n'))

if inch >=0:

inchesToCm = inch * 2.54

print (inch, 'inches is', format(inchesToCm, '.2f'), 'centimeters.\n')

temp = float(input('Give me a Fahrenheit temp to convert to Celsius.\n'))

if temp <= 1000:

celsius = (temp - 32) * (5/9)

print (temp, 'degrees Fahrenheit is', format (celsius, '.1f'), 'Celsius.\n')

else:

print ('Wrong input, too high.\n')

else:

print ('Wrong input, no negatives.\n')

else:

print ('Wrong input, no negatives.\n')

我嘗試過一個方案,但不知道如何合并下一個轉換,或是讓它恰到好處。在

^{pr2}$

謝謝你!我根據我們目前所學的知識,修改了你所列的格式。)我們還沒學會系統出口我還不得不在最內層的循環中插入count=3,因為pgm仍然希望在有效輸入下運行3次。我知道這是用While循環。但是,有沒有一種方法仍然可以作為一個“For”循環來完成呢?還是不可能?(希望下面的對齊方式很好,因為我在記事本中修改了它。)count = 0

while count < 3:

miles = float(input('Type miles to be converted to km.\n'))

if miles >= 0:

milesToKm = miles * 1.6

print (miles, 'miles is', format(milesToKm, ',.1f'), 'kilometers.\n')

count = 0:

while count < 3:

inch = float(input('Give me inches to convert to cm.\n'))

if inch >=0:

inchesToCm = inch * 2.54

print (inch, 'inches is', format(inchesToCm, '.2f'), 'centimeters.\n')

count = 0:

while count < 3:

temp = float(input('Give me a Fahrenheit temp to convert to Celsius.\n'))

if temp <= 1000:

celsius = (temp - 32) * (5/9)

print (temp, 'degrees Fahrenheit is', format (celsius, '.1f'), 'Celsius.\n')

count = 3

else:

print ('Wrong input, too high.\n')

count+=1

else:

print ('Wrong input, no negatives.\n')

count +=1

else:

print ('Wrong input, no negatives.\n')

count +=1

總結

以上是生活随笔為你收集整理的for循环false 终止 python_python3.5.1给用户3次无效的尝试,然后终止pgm(Simple FOR循环)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。