def main():
name=input("Enter your name: ") #just write our name nothin important
print (name, "is Swag")
value1=int(input("enter a value: ")) #takes in the number without doubt
print(value1)
value2=float(int("Enter a fraction: ")) #heres our problem but what?
print(value2)
main()
只是一个简单的程序,我玩用左右,但它显示了这个错误,因为你都可能想知道:如何采取一个整数,并使用一小部分就可以了
我写例如1/2一个这表明,除非你使用eval
(这是不安全的,所以我不能建议)
Traceback (most recent call last):
File "C:\Users\waliu\Documents\Waliur Uni stuff\Information
systems\Python Programs\Samples\apparently fractions.py", line 8, in
<module>
main()
File "C:\Users\waliu\Documents\Waliur Uni stuff\Information
systems\Python Programs\Samples\apparently fractions.py", line 6, in main
value2=float(input("Enter a fraction: "))
ValueError: could not convert string to float: '1/2'
Python做,如果你问好听,像PM2Ring评估分数... –
忘了那一个。好。我开始认为这可能是重复的。它是,在某种程度上:https://stackoverflow.com/questions/1806278/convert-fraction-to-float –
谢谢你的帮助 – PL8YR