+ 2

Need help to add a experience system to my code plz.

Experience system https://code.sololearn.com/c9dlyFVFgZHL/?ref=app

11th Jun 2017, 11:23 AM
Albert Blaauw
Albert Blaauw - avatar
8 Respostas
+ 6
This is my answer to your base case previously posted (next deleted)... try to adapt it ^^ Also, try to truely factorialize the code for a question() function, instead repeating it by defining question1(), question2() and so on... ;) xp = 0 while True: x = input("plz enter your answer here: ") if x == "2": print("correct") xp += 10 break else: print("incorrect") break ... but your while loop is unnecessary, as you break it anyway... better and shortener to write: xp = 0 x = input("plz enter your answer here: ") if x == "2": print("correct") xp += 10 else: print("incorrect")
11th Jun 2017, 12:47 PM
visph
visph - avatar
+ 5
# No absolute need of object model (and so class), but you could also ^^ # Simple factorization, with question and answer as parameters: def question(ask,ans): global experience global score x = input(ask+"\nInsert your answer plz: ") if x == ans: print("Correct!") experience = experience + 10 score = score + 1 else: print("Your answer was incorrect!") experience = 0 score = 0 print('Plz solve the following equations.') question("""Question 1.1 1 + 1 = ? ""","2") print("""Question 1.2 solve for z. """) x = randint(1, 100) y = randint(1, 100) question("if {} + {} = z".format(x,y),str(x+y)) print("Your Score is: " + str(score) + " points") print("Your Experience gained is: " + str(experience) + " exp") # Better way to compare numbers rather than strings, because for example, "2 " will be considered as a bad answer if good answer is"2" :P
11th Jun 2017, 6:38 PM
visph
visph - avatar
+ 1
oky so this is the basic code I wnant too add a system which give you exp like in sololearn fir now the program is very basic. there is one already but I dont know if it will work at the end as it is supposed to.
11th Jun 2017, 11:25 AM
Albert Blaauw
Albert Blaauw - avatar
+ 1
my idea is to give the user exp for a 20 question quiz and then later add a login. after a quizz the exp should be added and placed on the profile of the person logged in. The score system is there for current quizz the person is doin. nothing more only to give a result at the end of the quizz.
11th Jun 2017, 11:28 AM
Albert Blaauw
Albert Blaauw - avatar
+ 1
Ty again I need some time to process this lol. your the best!!!
11th Jun 2017, 6:41 PM
Albert Blaauw
Albert Blaauw - avatar
0
oky the question is up again with the whole code only 2 questions for now..
11th Jun 2017, 11:29 AM
Albert Blaauw
Albert Blaauw - avatar
0
ty man ill try it I appreciate it .
11th Jun 2017, 6:04 PM
Albert Blaauw
Albert Blaauw - avatar
0
I was thinking of factorailizing my code but I dnt know how im goin to so that I.need to think abt thst 1. I wanted to remove the while loop but didn't want to screw it up bcs I didnt have much time. incase I break it.it was still part of off my old code where I was trying to give the user inf retry's
11th Jun 2017, 6:09 PM
Albert Blaauw
Albert Blaauw - avatar