- 1
Just started learning python but came across a problem I need help solving
Write a multiple choice quiz on a topic of your choosing. There should be 5 questions and each question should have 3 possible answers. Use if statements to tell the user if they are correct and to keep a running total of their score. At the end of the quiz display a suitable message to the user - - - either "You're a genius", " Not bad", or "Must try harder" depending on the user's score. Thanks in advance.
19 odpowiedzi
+ 6
Did you "need help solving" or are you expecting someone write it entirely for you? @@
If you really ask for help, share your try (show us your code attempt), and be more accurate in your question: we doesn't have problem to write an entire script, but on some particular subtask... or we are planning a project not related to our skills, so we need to continue learning before and train on easiest/smallest project/task ;P
+ 5
@Daniel: I think he definitively don't want to try, but he's only expected someone do it for him ;P
@Tal: why do you need to finish it before saturday? If you cannot even start write some code, you're not able to reach that goal, and just need to be patient, learn and experiment basics before having such (not really hard) project ^^
+ 4
Exactly, try to do something and we will gladly help you if you have any problems.
+ 4
<< How do I make it so the machine will know that those lines are questions with multiple possible answers in which only one is correct? >>
The first goal is to display to user the question and the list of possible answers: just use print("text") as you do for the result print("x marks");
The second goal is to ask user for its answer: the key is in use of the function input() wich you probably have already study (if not, you need to continue your course)
<< How do I make it so it assigns scores of 2s or 0s to a correct or wrong answer?
How do I make it keep count of the scores and sum them up at the end? >>
You need a first variable to store the score: initialize it to zero at begin, and add earned points to it each time user give a good answer (if all good answers give as much points as each others, you can just add one to count the number of good answers and multiply by the numbers of points of one good answer to get the total points earned)
You need also a second variable to store the user answer, wich you compare to the expected one (the good answer among the choice)...
If the answer equals the good answer, then you add the value earned (or one to just count good answers) to the variable storing the score
Try again: solutions are already written and waiting for you (many versions, from simplest using imperative programming, to more advanced using object oriented programming, through the intermediate ones using functional programming)...
+ 4
@Tal wrote: << I tried rewriting the first 2 questions. Tell me what you think before I proceed >>
You are touching the advantage of doing functionnal programming rather than imperative ;) (but I will talk about that later, to not confuse you too much ^^)
Well, that's better, but still not good ;)
Have you try to run it?
If you run it, you will see the first string printed and an error message: error messages need to be read closely to get information about what and where... even if the line pointed is not always the one where the error is located (but often just before, meaning previous line). In this case, the error is explicit: 'word' is not defined, because you seems to not have right understood how function works, as well as how getting an user input ^^
You correctly define a function:
def myfunction(argument): # could have many argument names, comma separated
print(argument) # do anything you want inside the function
But for calling your function, you need to pass a value, so:
myfunction("Hello!")
... or:
text = "Hello!"
myfunction(text)
But if you don't assign a value to the variable used as argument value, you will have the error message mentioned above.
Anyway, the goal of your user function is that your 'word' variable will store the user input, and your way is not the right one: I told you about the input() function: it's a built-in function, as the print() do output, but returning a value... argument expected will be printed just before waiting for the user entry:
user_value = input("What's your answer? ") # ending space avoid user entry to stick last character of the string
Incidentally, you miss the first question, you directly print only the answers choice...
Try again, even on only one question: when your code will be working, you will just repeat same process for each (and we maybe will talking again about the first advantage of functionnal programming -- avoid repeat of similar block of code), and then write the final part about the result.
+ 3
share your code exactly
+ 3
Try to begin your own code and next we can help you
+ 3
Well, I can do it yes, but if you are studying you must to research to do something. You can check input and output in SoloLearn Python Course to begin something.
+ 2
It does not make me laugh ... it questions me: did you really learn something and do a real attempt, or do you try to pretend?
> keywords are case sensitive and needs to be correctly written: 'print' is not 'Print', or 'if' is not 'If'
> anything which is not enclosed by quotes should respect the language syntax/rules and need to be correctly indented in a language as Python
> any sign not enclosed by quotes is very signifiant, and a semi-colon (;) is not the same thing than a colon (:)
> anything not enclosed by quotes and not referenced as keyword of the language is attempted to be interpreted as custom identifiers (variable or function name) in an expression (a formula) and need to be significant for the language used
> conditionals have to be explicit, and most of the time require to compare two values... using an 'if' statement with only a variable will throw an error related to an undefined variable if no value have been assigned, and will be only false if the value assigned to the variable contains False (the Python boolean value), 0 (number zero), empty string (nothing but enclosed in quotes), empty list or empty object.
Appart of that, your logic is correct, but you are far away of a working script ^^
You need also to think to count the number of correct answer to be able to "display a suitable message to the user"
Try once more :P
+ 1
Try to begin
+ 1
Exactly visph. For much of us is relatively easier do that kind of codes but then, what is the purpouse? He dont learn. Next week he will ask to do a new code.
+ 1
@Daniel and visph: ahahahaha, you guys. It's not that I'm lazy or anything. Fine, I'll try to see if I can cook up something and bring it here for your opinions. Thanks
0
I don't know how... Can you give me some ideas on codes that can give me 3 possible outputs and how to assign those outputs to variables?
I just want an example I can use as reference
0
Hello guys, I tried writing something. Don't laugh now...
Pls give me your feedback on it.
https://code.sololearn.com/cl14np5G72n9/?ref=app
0
This was after a few lessons. I really tried, and by my current abilities, this was the best I could do.
> I understand what you meant about the conditionals and syntax - that's exactly my problem. I do not know how to correlate the language syntax to the given problem.
How do I make it so the machine will know that those lines are questions with multiple possible answers in which only one is correct?
How do I make it so it assigns scores of 2s or 0s to a correct or wrong answer?
How do I make it keep count of the scores and sum them up at the end?
I couldn't get that from the lessons.
Pls explicate...
0
Alright, visph. Let me give it another shot
0
Visph, I tried rewriting the first 2 questions. Tell me what you think before I proceed
https://code.sololearn.com/cwAvyM8kSj2g/?ref=app
- 1
I can't share my code because I do not have a code to share. I just started learning so I am not proficient enough to write it out and I need to finish it before Saturday, but I have a precise set of steps I believe can solve it. What I need is:
1. Five lines of code where each line has 3 possible outputs that assigns values of 3, 2, or 1 to variables.
2. Variables must be summed up at the end of code (five lines- I don't know that technical term for it)
3. Print an output of "You're a genius" for a sum greater 11;
Print an output of "not bad" for a sum between 6 and 10;
Print an output of "Must try harder" for a sum equal to less than 5.
What I need is someone to help me write out code that follows this scheme. Thanks and sorry for the trouble.
- 1
Pardon me?