I do not understand why I get a ValueError when I want to transform a calcul string into float. I would like an issue because I am stuck up.
(The aim of my code is to create random equations with increasing level depending on question number.)(I am still a beginner, sorry if my code is unmethodical (and in french too).)
:)
There is my code:
(input)
from random import *
def Numéro_Question():
global NuméroQuestion
NuméroQuestion+=1
print("\t~ Question {} ~\t\n".format(NuméroQuestion))
def Calcul2():
PremierChiffre=randint(0, NuméroQuestion*5+5)
Question=str(PremierChiffre)
for i in range(1,NuméroQuestion+1):
SigneDeCalcul=["+","*","-"]
SigneChoisi=str(choice(SigneDeCalcul))
x=str(randint(0, NuméroQuestion*5+5))
Question=Question+SigneChoisi+x
print(type(Question))
QuestionNumérique=float(QuestionNumérique)
QuestionEcrite=Question+" = "
Question=float
Réponse=input(QuestionEcrite)
NuméroQuestion=0
Raté=0
while Raté<3:
Numéro_Question()
Calcul2()
print("\n\n")
(output)
(The output changes each time you execute the program because it gives random number)
~ Question 1 ~
<class 'str'>
Traceback (most recent call last):
File "main.py", ligne 26, in <module>
Calcul2()
File "mai,.py", ligne 17, in Calcul2
QuestionNumérique=float(QuestionNumérique)
ValueError: could not convert string to float: '3*6'