Day 16: 100 Days of Code: While True loop

Sdílet
Vložit
  • čas přidán 1. 08. 2024
  • Let's cheat our way through a `while` loop so we never have to suffer the indignity of an infinite loop ever again. Join #replit100daysofcode here join.replit.com/python
    Tutorial link: replit.com/@replit/Day-16100-...
    00:00 while True loop
    01:45 Make it stop
    03:36 Common errors
    05:11 Fix my code
    05:22 Day 16 challenge
    06:18 Share your code
    06:35 Next up
  • Zábava

Komentáře • 58

  • @damonjohnson7589
    @damonjohnson7589 Před rokem +12

    You make this so fun....and whilst albeit sometimes cheesy, more often flat out funny. Thank you!

    • @replit
      @replit  Před rokem +10

      Cheesy is my entire brand!

  • @jorencuppens1434
    @jorencuppens1434 Před rokem +7

    i like your instructions even while i know every thing

  • @kultemail
    @kultemail Před rokem +8

    print("Fill in the blank lyrics!")
    print("Figure out the missing word as quickly as you can!")
    counter = 1
    while True:
    lyrics = input("Never gonna ____ you up.
    ")
    if lyrics == "give" or lyrics == "Give":
    print("Well done!")
    break
    else:
    counter +=1
    print("Nope, try again.")
    if lyrics == "give" or lyrics== "Give":
    break
    print("Thanks for playing")
    print("You got the correct lyrics in", counter, "attempt(s).")

    • @FinancialEducation89
      @FinancialEducation89 Před rokem +1

      Bro counter should be equal to 0 because if counter equals to 1 then the computer will start counting from 1 instead of zero.
      and what happens is that if the user gets it on their 1,2,3,4,or 5 or whatever attempt ,the comp will always add one extra 1 with that because the counter =1 .

    • @vamsi5509
      @vamsi5509 Před 10 měsíci

      no bro it wont...because when the condition is true it will immediately terminate out of the loop and it will considered as 1 attempt....if 0 then attempts will also be 0...that is the reason to balance it they put counter=1@@FinancialEducation89

    • @user-dg4bn2ws9y
      @user-dg4bn2ws9y Před 7 měsíci

      yeah make it to like 1000 cuz that shgould be the maz idc whjy but why u in ym face girl ur break thjenak juhj gho fohg gnthe bathn room oh sorry my 1 yr old brother took conrol bt yeah make it to 1000 cua that can be trhe make if not then just brkeakk then you lknow thatsd tothere is no end @@FinancialEducation89

    • @VeronicaThibodeaux
      @VeronicaThibodeaux Před 8 dny

      Thank you so much! I now understand that break has to come before else and I unnderstand counter better too. 😂

    • @VeronicaThibodeaux
      @VeronicaThibodeaux Před 8 dny

      @@FinancialEducation89 the counter = 1 because people start counting at 1 not zero

  • @youknowme1153
    @youknowme1153 Před rokem +3

    print("done")
    counter=0
    while True:
    print("fill in the blank")
    print("now from the top make it drop thats some___ ")
    counter += 1
    guess=input("what is it: ")
    if guess=="wap":
    print("you did it")
    else:
    print(" keep trying you have made",counter,"trys")
    if guess=="worship and prayer":
    break
    print("thanks for playing")

  • @surfineer
    @surfineer Před rokem +6

    Did you just Rick-Rolled me? :D

    • @replit
      @replit  Před rokem +7

      I bought costumes for that Rick Rolling. PLURAL!

  • @therickrollmaster69420

    You have an amazing taste in music.

  • @SutPlayz
    @SutPlayz Před 6 měsíci

    counter = 0
    print("Fill in the lyrics")
    while True:
    A = input("I can buy myself _____")
    counter += 1
    if A.lower()== "flowers":
    print("Correct!")
    print("Youtook",counter,"attempts")
    break
    else:
    print("Try again!")

  • @user-ri1wp7do5s
    @user-ri1wp7do5s Před 7 měsíci +1

    Here's mine. For the Header and Title, I used a string I learned previously so they are centred (not in the 100 Days of Code).
    Don't forget guys, you can spice your code up a bit. Some people use colours in theirs. The main important thing is you understand the code and know what you're typing. Think of something you want to add in and google it adding 'Python' at the end of your question. It may be that David covers it, later in this series!
    #Page Header
    txt = "The Lyrical Genius Game"
    new_str = txt.center(50)
    print(new_str)
    #Title
    txt = "Guess The Missing Lyric"
    new_str = txt.center(50)
    print(new_str)
    #counter
    counter = 0
    #Song 1
    print()
    print("Song 1:")
    print()
    while True:
    lyrics1 = input("It's a Nice Day for a _____ Wedding: ")
    counter += 1
    if lyrics1 == "white":
    print()
    print("That took you", counter, "attempts!")
    break
    else:
    print()
    print("Sorry, try again.")
    #Song 2
    print()
    print("Song 2:")
    print()
    while True:
    lyrics2 = input("You better lose yourself in the music, the ______ you own it: ")
    if lyrics2 == "moment":
    print()
    print("That took you", counter, "attempts!")
    break
    else:
    print()
    print("Sorry, try again.")
    #Song 3
    print()
    print("Song 3")
    print()
    while True:
    lyrics3 = input("You promised me ________ was waiting for me: ")
    if lyrics3 == "broadway":
    print()
    print("That took you", counter, "attempts!")
    break
    else:
    print()
    print("Sorry, try again.")
    #End
    print()
    print("Thanks for playing!")
    print("Please click 'stop' then click 'run' to play again.")

  • @vinnieg6161
    @vinnieg6161 Před rokem +1

    after endless mistakes I'm so happy when I finally figure something out.
    The last solution was confusing to me. i didn't know you could have another if after the else statement, I thought you had to slide it in between with the ''elif'' statement?

  • @samardeepsingh-jo4nw
    @samardeepsingh-jo4nw Před 2 měsíci

    while True:
    color = input("Enter a color: ")
    if color == "red":
    break
    else:
    print("Cool color!")
    print("I don't like red")

  • @adiahheart9413
    @adiahheart9413 Před rokem

    Thank you, this was fun!

  • @べべべ
    @べべべ Před 9 měsíci +1

    He just rickrolled us!

  • @bollywood8Dvibes
    @bollywood8Dvibes Před 10 měsíci

    Took me some time to figure out the code but here's what i came with:
    print("Fill in the blank lyrics!
    ")
    count=0
    print("I put my ___ on you.")
    while count

  • @morpheus_circuit
    @morpheus_circuit Před 7 měsíci

    Here is mine Fill-in-the blank for Comfortably Numb by Pink Floyd
    print("Fill-in the blank lyrics!")
    print("Figure out the missing word as quickly as you can! Please only lowercase letters")
    Answertally = 0
    while True:
    print("There is no ____ you are receding")
    answer = input("What is the missing word? ")
    if answer == "pain":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("A distant ship smoke on the _______")
    answer = input("What is the missing word? ")
    if answer == "horizon":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("You are only coming through in _____")
    answer = input("What is the missing word? ")
    if answer == "waves":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("Your ____ move but I can't hear what you're saying")
    answer = input("What is the missing word? ")
    if answer == "lips":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("When I was child a had a _____")
    answer = input("What is the missing word? ")
    if answer == "fever":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("My hands felt just like two ________")
    answer = input("What is the missing word? ")
    if answer == "balloons":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("Now I've got that _______ once again")
    answer = input("What is the missing word? ")
    if answer == "feeling":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("I can't explain you would not __________")
    answer = input("What is the missing word? ")
    if answer == "understand":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("This is ___ how I am")
    answer = input("What is the missing word? ")
    if answer == "not":
    Answertally += 1
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    while True:
    print("Iiiiiiiiiiii, have become, C O M F O R T A B L Y ____ 💊")
    answer = input("What is the missing word? ")
    if answer == "numb":
    Answertally += 1
    break
    elif answer == "N U M B":
    Answertally += -10000000000000000000000000
    break
    else:
    Answertally += 1
    print("Try again")
    print("Correct!")
    print(f"Well done. It took you {Answertally} attempts to get all of the right answers")
    Note: I didn't expect getting rick rolled lol

  • @terfio1897
    @terfio1897 Před rokem

    after much time i finnaly figured it out but i didnt know how to do the last part
    lyrics = ""
    attempts = lyrics
    print("Fill-in the blank lyrics")
    while lyrics != "give":
    print("Never gonna ____ you up")
    lyrics = input(" ")
    if lyrics == "give":
    print("Those are the right lyrics")

  • @shaikaslamoo31
    @shaikaslamoo31 Před rokem +1

    Why I am not able to solve this problem???

  • @wittx1234
    @wittx1234 Před 10 měsíci

    I manage to write the code and run successfully without using any counter. Am I correct? But after seeing almost everyone here using counter, I decided to add it as well:
    print("Fill in the blank lyrics!")
    counter = 0
    while True:
    print("Fading out again, I feel the _____ in my bloodstream")
    lyrics = input("Type in the blank lyrics and see if you are smart: ")
    counter += 1
    if lyrics == "chemicals burn":
    break
    else:
    print("Nope, incorrect. Keep going.")
    print("Finally!", "It only took you", counter, "attempts!")
    Original code: (it can't count the number of attempts though)
    print("Fill in the blank lyrics!")
    while True:
    print("Fading out again, I feel the _____ in my bloodstream")
    lyrics = input("Type in the blank lyrics and see if you are smart: ")
    if lyrics == "chemicals burn":
    break
    else:
    print("Nope, incorrect. Keep going.")
    print("Finally!" "You did it!")

  • @Sandeep_jha
    @Sandeep_jha Před 7 měsíci

    correct_lyric = "give"
    attempts = 0
    while True:
    attempts += 1
    user_input = input("Never going to ______ you up: ").lower()
    if user_input == correct_lyric:
    print(f"Well done! It only took you {attempts} attempts.")
    break
    else:
    print("Nope, try again.")

  • @apheru
    @apheru Před 6 měsíci

    print("Fill-in the blank Lyrics!")
    print()
    print("type in the blank lyrics, see if you're as cool as me")
    print()
    count = 0
    while True:
    word = input("Never going to ____ you up: ")
    print()
    count += 1
    if word == "give":
    print(f"Well done, it only took you {count} attempts!")
    break
    else:
    print("Nope, try again")
    print()

  • @thefigureshow
    @thefigureshow Před rokem

    I Think It's Wrong: I noticed in the answer to the code in the challenge that if the user inputs "Miss" the game loops whereas if they enter "miss" the game ends. Is that its intended purpose? if so then why add the first if statement in the first place?
    it should be:
    if lyrics == "miss" or lyrics == "Miss":
    break
    correct me if I'm wrong.

  • @KisanduWebWizard
    @KisanduWebWizard Před rokem +1

    I complete chalenge in a better way. check my code.
    name = input("Name : ")
    name = input("Name : ")
    print()
    print("Fill in the blanks", name)
    print('(Type in the blank and see if you are as cool as me)')
    print()
    counter = 1
    while True:
    print('Never going to ____ you up.')
    a = input("Word : ")
    if a =="give":
    print('welldone',name,'you got correct lyrics in',counter,'attemt')
    break
    else:
    print("nope, again!")
    counter+=1

  • @pathseven8398
    @pathseven8398 Před rokem

    here's my rick roll guess counter
    print("Guess the lyric")
    print()
    counter = 0
    while True:
    lyric = input("Never going to ____ you up? ")
    counter += 1
    if lyric == "give":
    print("Correct.")
    if counter < 2:
    print("A person of culture I see, it only took you one guess")
    elif counter < 3:
    print ("It took you", counter, "times... a little slow I'd say")
    elif counter > 3:
    print("your still a fool since it took you", counter, "times to guess")
    break
    else:
    print("Try again you fool")

  • @edgarramirez4936
    @edgarramirez4936 Před rokem +2

    I can't figure out how to add the amounts of attempts

    • @aeonianlance7255
      @aeonianlance7255 Před rokem

      Hint?
      hint = input
      if hint ==
      I can't post full answer of this challenge without David's permission . Trust me, this challenge was VERY easy.

    • @edgarramirez4936
      @edgarramirez4936 Před rokem +3

      @@aeonianlance7255 When it comes to everything else I have completed it, but I can't make the code tell how many attempts a person has done after finishing

    • @aeonianlance7255
      @aeonianlance7255 Před rokem +2

      @@edgarramirez4936 oh, links are forbidden.
      So:
      tryAgain = 0
      while True != "put":
      tryAgain += 1
      Don't surrender, bro. You can do it!

    • @edgarramirez4936
      @edgarramirez4936 Před rokem +1

      @@aeonianlance7255 thank you

  • @adnanshafiq991
    @adnanshafiq991 Před rokem +1

    Please guide about no of attempts?

    • @motlalepula_s01
      @motlalepula_s01 Před 11 měsíci

      am struggling too

    • @MickRayzee
      @MickRayzee Před 6 měsíci

      you need a variable at the top
      then increment it when the loop starts ie.
      count = 0
      while True:
      count += 1
      then your if statement to check it the word matches... if you have count as 1 to start put count at the bottom

  • @vamsi5509
    @vamsi5509 Před 10 měsíci +1

    I wrote the code without using counter at all and it worked...can we write like this or i'm wrong can anyone help with this

    • @wittx1234
      @wittx1234 Před 10 měsíci

      Same here! I'm also not sure if I should add the counter or not.

  • @erjonrashiti7887
    @erjonrashiti7887 Před rokem

    Please help me in this challenge i cant do it

  • @same-kun8016
    @same-kun8016 Před 3 měsíci

    POV: You smell something sus
    me: Oh I wonder what's today challenge
    *reading
    my mind: Never going to...wait a second...smth sus here *imaginary music ON
    my mind: Nah no way he gonna do that, maybe its a different song :>
    *1 sec later, rick rolled
    me: DAMNN ITT

  • @zurr9074
    @zurr9074 Před 9 měsíci

    ```
    lyric = "give"
    attempts = 0
    print ("Fill in the blank lyric! Type in the blank lyric and see if you are as cool as me. Good Luck!")
    while True:
    blank_lyric = input("Never going to _ you up!: ")
    if blank_lyric == lyric:
    print(f"Nice! Never going to {lyric} you up!")
    attempts +=1
    print (f"It took you {attempts} attempt(s) to finish, good job.")
    break
    elif blank_lyric != lyric:
    print ("Nope try again.")
    attempts +=1
    ``` How'd I do?

  • @jibbiriffs
    @jibbiriffs Před rokem +3

    counter = 0
    print('\033[34m==\033[33mThe Lyric Game\033[34m==\033[0m')
    while True:
    print('::Guess the Lyric::')
    print("Say your prayers little one don't forget my ___")
    lyricGuess = input('What is the missing lyric? ')
    counter += 1
    if lyricGuess != 'son':
    print("Guess again! You've made", counter, "attempts!")
    else:
    print('Congratulations! You guessed the correct lyric, in', counter, 'attempts!')
    break

  • @matfrei9589
    @matfrei9589 Před měsícem

    # Day 16
    print('Fill in the blank lyrics!')
    print('Figure out the missing word as quickly as you can!')
    counter=0
    while True:
    print(' ')
    print('Never going to ______ you up.')
    x= input(' ').lower()
    counter+=1
    if x!= 'give':
    print('Nope, try again.')
    if x == 'give':
    break
    print('')
    print('Well done! It only took you',counter,'attempts.')
    print('*** Finished ***')

  • @silenthiccups
    @silenthiccups Před 7 měsíci

    print ("Name the lyrics")
    print("")
    counter = 0
    while True:
    guess = input("Guess the following lyrics of this song: Never going to ____ you up. Whats the missing word?:")
    if guess != "give":
    counter += 1
    print ("Try again. Your number of attempts:", counter)
    else:
    counter += 1
    print ("Correct, the number of times it took you to get it right was,", counter)
    break

  • @inhtran3687
    @inhtran3687 Před rokem

    counter = 0
    print("\033[34m","Fill in the blank lyrics!","\033[0m")
    print("Type in the blank lyrics and see if you are as cool as me.")
    print("Here's the lyric")
    print("\033[33m","On a dark ______ highway","\033[0m")
    while True:
    answer = input("Enter the word: ")
    counter += 1
    if answer == "desert":
    break
    else:
    print("Nope, try again. This is the","\033[32m",counter,"\033[0m","attempt")
    print("Correct! You're a master");

  • @swearexus1257
    @swearexus1257 Před 5 měsíci

    Wasn't too hard actually. Here's my code:
    print("Fill-in the blank lyrics!")
    print("Type in the blank lyrics, see if you're as cool as me")
    print()
    print()
    print()
    counter = 1
    while True:
    print("Never going to ____ you up")
    print()
    missingWord = input("What word is missing in the blank lyrics?: ")
    print()
    if missingWord == "give":
    print("Right answer.")
    break
    else:
    counter += 1
    print("Wrong answer. Try again!")
    print()
    print()
    print()
    if counter == 1:
    print("You found the missing lyrics in 1 atempt.")
    elif counter >= 2:
    print("You found the missing lyrics in", counter, "atempts.")

  • @michaelukachi-us7hv
    @michaelukachi-us7hv Před rokem

    EXPLAIN.......IN YOUR FIRST EXAMPLE
    counter = 0
    while true:
    answer = int(input("Enter a number: "))
    print("Adding it up!")
    counter += answer
    print("Current total is", counter)
    addAnother = input("Add another? ")
    if addAnother == "no":___________________WHAT IF I ADDED A NUMBER INSTEAD OF A TEXT YES OR NO
    break
    print("Bye!")

  • @SadisticFrog
    @SadisticFrog Před 8 měsíci

    While loops are if statements on steroids

  • @user-zy9ih3uy3n
    @user-zy9ih3uy3n Před rokem

    print("Vamos a ver que sabes de refranes")
    counter = 1
    while True:
    refran = input("Sin riesgo, no hay: ")
    if refran == "Gloria" or refran == "gloria":
    print("Muy bien, tu si sabes de refranes, lo hiciste en", counter, "intentos")
    break
    else:
    print("Revisa mas refranes")
    counter += 1

  • @gordonroo
    @gordonroo Před rokem +1

    6:15 click this i dare you

  • @Jonas_w
    @Jonas_w Před rokem

    print()
    name =input ("Vad heter du?: ")
    counter=1
    while True:
    older = int(input("Hur gammal är jag ?: "))
    if older == 25:
    counter+=older
    print("Du har rätt",name.upper())
    break
    go= input ("Vill du gå vidare? : ")
    if go !="ja":
    print("Lycka till")
    break
    else:
    print ("Du har fel",counter,"gånger",name.upper())
    counter+=1
    else:
    print ("Hejdå")