Day 012 - Project 12 : I've broken some code!

If you have any questions, comments or issues with this project please post them here!

Hmmm. I actually did not fix the code the way the answer suggested. i could not remember the correct syntax for integers in the input statement BUT, i did get the code to work by changing the integer into a string so, i guess that’s one more way to skin a cat?!
here’s what I did vs. what the answer actually was.
My code:

print("100 Days of Code QUIZ")
print()
print("How many can you answer correctly?")
ans1 = input("What language are we writing in?")
if ans1 == "python":
  print("Correct")
else:
  print("Nope🙈")
ans2 = input("Which lesson number is this?")
if ans2 > ("12"):
  print("We're not quite that far yet")
elif(ans2== "12"):
  print("That's right!")
else:
  print("We've gone well past that!")

Replit’s answer:

print("100 Days of Code QUIZ")
print()
print("How many can you answer correctly?")
ans1 = input("What language are we writing in?")
if ans1 == "python":
  print("Correct")
else:
  print("Nope")
ans2 = int(input("Which lesson number is this?"))
if(ans2 > 12):
  print("We're not quite that far yet")
elif(ans2 == 12):
  print("That's right!")
else:
  print("We've gone well past that!")

Hey @socraticmudd, welcome to the forums!

Could you explain whats the problem you are having with you code?

Hi @socraticmudd

In addition to @hugoondev 's welcomes I wanted to ask for some more information here.

In order for the community to suggest ideas to help you solve your code issue it would be useful to share a link to your Repl, not post your entire code in the message as it is difficult to see if there are indentation errors etc.

Any error messages that you see appear when you attempt to run your code would also be useful to share here.

1 Like

Hello Hugo,
I guess I didn’t really have a problem as much as the solution i came up with worked but, was actually inaccurate according to Replit. I changed the integer ‘12’ to a string by inserting quotes around it when i should have used: ans2 = int(input(“Which lesson number is this?”)). I could not remember whether the ‘int’ syntax was supposed to go after the ‘input’ syntax or where the parenthetical s were supposed to go so, I improvised. I am only on day 12 but, do the future lessons offer a reminder of some of the code we have learned so far or should we rely on notes?

1 Like

As you said earlier, there are multiple ways to skin a cat. So if it works and doesn’t lead to unexpected issues, then great! You have learned :partying_face:
As you learn more you might see how one way is better, or more efficient, or simple clearer, or…

Future lessons offer a few reminders, but mostly it is up to you to search for the answers (gets better into your head that way).

2 Likes

I don’t know, maybe it could happen!

Not going to lie I took little help. But here’s the answer

print("100 Days of Code QUIZ")
print()
print("How many can you answer correctly?")
ans1 = input("What language are we writing in? ")
if ans1 == "python":
  print("Correct")
else:
  print("Nope🙈")
ans2 = int(input("Which lesson number is this? "))
if(ans2 > 12):
  print("We're not quite that far yet")

elif (ans2==12):
  print("That's right!")
else:
  print("We've gone well past that!")
1 Like

On it says that there is a syntax error. The Repl is running perfectly fine though.

print()
print("How many can you answer correctly?")
ans1 = input("What language are we writing in?")
if ans1 == "python":
  print("Correct")
else:
  print("Nope")
ans2 = input("Which lesson number is this?")
if(int(ans2)>12):
  print("We're not quite that far yet")
elif(int(ans2)==12):
  print("That's right!")
else:
  print("We've gone well past that!")

The syntax error is at the end of print("Nope"). However, it is a completely valid line of code (in my terms).

When I run that code I get no errors.

1 Like

There is a red mark right below the end of the parathense on my screen.

I dont get it. Try refreshing

image

1 Like

i think its an issue with replit. i get same error some times valid code but random red dots. usually deleting and retyping works

doesn’t effect functionality though so unless he didn’t try to run it that not the issue

1 Like

I’m afraid I don’t quite understand the question, but I’ll give my best shot at providing a solution anyway :slight_smile:

You could store an dictionary of questions and correct answers, then just have a loop.

        import os
        quiz = {"What language are we writing in?": "Python", "Which lesson number is this?": "12"}
        for question in quiz.keys():
            os.system("clear")
            while str(input(question)) != quiz[question]:
                os.system("clear")
                print("Nope, try again!")
            print("Correct!")
            cont = input("Press Enter to Continue \n")

I’m not sure if that’s what you were looking for, but if not please explain for specifically what you need help with :slight_smile:

Hi, can I please have my original topic back? I haven’t “broken a code” my question specifically says I have fixed the errors. I just want to add something extra into the code.

That is the name of the day 12 project, and we’re supposed to merge code help requests for 100 DoC into their respective master topics. (This is the one for day 12)

1 Like

@Firepup650,
A: Happy Birthday!
B: I disagree that his question should go here. It might be part of the 100 days, however, it’s closer to a question about adding a specific feature to it.

1 Like

Nevermind. I don’t need other replies to different questions about day 12. Just needed a specific answer to mine.

Thanks!

True, but as far as I’ve seen, other mods always merge those with the main DoC topic, so I’m just following what I’ve seen the other mods do.

2 Likes

And to answer your question (I understand now):
You can either use a variable, list, or dictionary to store the question/questions, then reference it in a while loop, such as:

    print(question)
    question_answer = "Answer"
    answer = input()
    while answer != question_answer:
        print(question)
        answer = input()
1 Like