Day 15: 100 Days of Code: Loops

Sdílet
Vložit
  • čas přidán 8. 09. 2024

Komentáře • 40

  • @ayyamguari6134
    @ayyamguari6134 Před rokem +17

    I am really loving this series. Building projects with fun comedy. Currently on Day 15. Thank you Replit and also bald man David haha😁😁

  • @vinnieg6161
    @vinnieg6161 Před rokem +7

    Probably the longest I've ever held interest in something other than playing games

  • @casualgamer3689
    @casualgamer3689 Před rokem +1

    . Started with some programming when i was 14 but never got the hang of it. I have now revisited my dream of wanting to code and having so much fun 🤩

  • @jibbiriffs
    @jibbiriffs Před rokem +7

    mine is
    print('\033[34m==\033[33mAnimal Farm\033[34m==\033[0m')
    uExit = ''
    while uExit != 'yes':
    animalInput = input('What animal do you want - cow, sheep, or duck? ').lower()
    if animalInput == 'cow':
    print('Moo 🐄 ')
    elif animalInput == 'sheep':
    print('bahh 🐏 ')
    elif animalInput == 'duck':
    print('quack 🦆 ')
    else:
    print("that's not a choice we've presented 😓 ")
    uExit = input('Do you want to exit? ' ).lower()
    if uExit == 'yes':
    print('Later! Have a lovely day 💖')
    Works nicely!

  • @sandeepchotalia1131
    @sandeepchotalia1131 Před rokem +2

    Short but basically giving the gist of the concept of the code
    exit = " "
    while exit != 'yes':
    ans = input("Which animal do you want ? : ")
    if ans == 'Cow':
    print("A Cow goes Moooo..!!")
    else:
    print("A ",ans," goes Awooga ?")
    print("")
    exit = input("Do you want to exit ? ")
    print("")

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

    enjoy the way u present the tutorial.... feel enjoy, happy, n relax

  • @fangyang5865
    @fangyang5865 Před rokem +2

    For the loop, you can also use
    mysum = 0
    for i in range(1,1001):
    mysum = mysum + i
    print(mysum)
    (1,1001 is just an example.)

  • @7Life-lights
    @7Life-lights Před 7 měsíci

    This is the correct code:
    I spent nearly 2 hours doing this, and I could not do it unless I saw Day 16:
    Animal=''
    while 'true':
    Animal=input('What animal do you want?')
    if Animal=='cow':
    print('A cow goes moo')
    elif Animal=='A lesser spotted lemur':
    print('Ummm...the lesser spotted lemur goes awooga')
    else:
    print('I dont know that animal, try again')
    exist=input('Do you want to exist?')
    if exist=='yes':
    break

  • @Tan066
    @Tan066 Před rokem +7

    This is the code I come up with:
    animals = ""
    while animals != "dog" and animals != "cat" and animals != "pig" and animals != "sheep" and animals != "horse":
    animals = input("What animals do you want?: ")
    if animals == "dog":
    print("Dog goes Woof! woof!")
    elif animals == "cat":
    print("Cat goes meow!")
    elif animals == "pig":
    print("Pig goes Oink! Oink!")
    elif animals == "sheep":
    print("Sheep goes baa! Baa!")
    elif animals == "horse":
    print("Horse goes neigh neigh! ")
    else:
    print()
    print(f'''{animals} is not on the list,
    you may choose between dog, cat, pig, sheep and horse''')
    print()
    exit = ""
    while exit != "yes" and exit != "exit":
    print("")
    exit = input("Exit?: ")

  • @adiahheart9413
    @adiahheart9413 Před rokem +1

    Thank you so much! It was a little hard but not too hard! I had lots of fun!

  • @emilioarango3901
    @emilioarango3901 Před 11 dny

    exit = "NO"
    while exit == "NO":
    animal = input("what animal do you want? ")
    if animal == "dog" or animal == "Dog":
    print("Woof")
    elif animal == "cat":
    print("miua")
    else:
    print ("I don't know that animal")
    exit = input("Exit?: ")

  • @ArsonalTech
    @ArsonalTech Před 4 dny

    Best toothy smile in the entire kingdom

  • @mendonchenrique
    @mendonchenrique Před 3 měsíci

    print('Farm Game')
    print()
    exit = ""
    while exit != "yes":
    animal = input('Choose an animal: ')
    if animal == "dog":
    print('Bark bark 🐶')
    elif animal == "cat":
    print('Miaaau 🐱')
    elif animal == "cow":
    print('Muuuu 🐮')
    else:
    print('Animal out of the list, choose between dog, cat or cow')
    print()
    exit = input('Do you wanna exit? ')
    print()
    print('Thanks for playing')

  • @7Life-lights
    @7Life-lights Před 7 měsíci

    This what I found and am not sure if it's correct:
    Animal=''
    while 'true':
    Animal=input('What animal do you want?')
    if Animal=='cow':
    print('A cow goes moo')
    elif Animal=='A lesser spotted lemur':
    print('Ummm...the lesser spotted lemur goes awooga')
    exist=input('Do you want to exist?')
    else:
    print('I dont know that animal, try again')
    if exist =='yes':
    break

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

    animal_sounds = {
    'Cow': 'moo',
    'Bird': 'tweet',
    'Cat': 'meow',
    'Lion': 'roar',
    'Rat': 'squeak'
    }
    while True:
    animal = input("What animal would you like to hear?: ").capitalize()
    if animal in animal_sounds:
    print (f"A {animal} goes {animal_sounds[animal]}")
    regen = input("Generate new sound? (yes/no): ").lower()
    if regen == "no":
    print ("Program Ending...")
    break

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

    x = input("what animal do you want?: ")
    if x == "cow":
    print("moo")
    else:
    print("uhmmm, the",x,"says moooooo...?")
    y = input("do you want to exit?: ")
    while y != "yes":
    print("pls")
    y = input("do you want to exit?: ")
    if y == "yes":
    print("
    :))))))")

  • @vineetrathod94
    @vineetrathod94 Před rokem +2

    i have written this code but what's wrong i cant understand?
    animal = input("what animal sound do u want? :")
    if animal == "cow" or animal == "goat":
    print("muhh")
    counter = 0
    while counter

    • @kristianrjsYT
      @kristianrjsYT Před rokem +2

      I took your code, changed some things around, cleaned it up a bit and managed to make it work. Rather than having multiple loops and if statements I wrapped a single if, elif and else statement in 1 single while loop. I also used a string instead of an int for your looping condition. Sorry, I wish I could explain this better but I'm still a noob lol, here's what I did, hope it makes sense to you. Good luck!
      exit = ""
      while exit != "yes" :
      animal = input("what animal sound do u want? :")
      if animal == "cow" or animal == "goat":
      print("muhh")
      elif animal == "lion" or animal == "tiger":
      print("roar")
      else:
      print("Sorry, please enter either cow, goat, lion, or tiger")
      exit = input("Would you like to exit?")

    • @ayradizem2770
      @ayradizem2770 Před rokem

      you need to add the keyword break in the end of your loops that it stop when it's true and it not show you the print of else , like this in your code :
      animal = input("what animal sound do u want? :")
      if animal == "cow" or animal == "goat":
      print("muhh")
      counter = 0
      while counter

    • @vineetrathod94
      @vineetrathod94 Před rokem

      @@ayradizem2770 i am stuck in day 28 task plz have a look at this...
      import random
      import time
      import os
      #print("Battle Time ⚔")
      while True:
      def character(name, type):
      if type == 'human':
      return random.randint(50, 75)
      elif type == 'elf':
      return random.randint(75, 100)
      elif type == 'wizard':
      return random.randint(100, 125)
      elif type == 'orc':
      return random.randint(125, 150)
      name1 = input("Name ur Legend :")
      print(name1)
      type = input("Character type (human, elf ,wizard, orc) :")
      print(type)
      print()
      health = character(name1, type)
      print(f"{name1}'s health stats are {health}")
      strength = character(name1, type)
      print(f"{name1}'s strength stats are {strength}")
      print()
      print("Who are they Battling?")
      print()
      name2 = input("Name ur Legend :")
      print(name2)
      type = input("Character type (human, elf ,wizard, orc) :")
      print(type)
      print()
      health = character(name2, type)
      print(f"{name2}'s health stats are {health}")
      strength = character(name2, type)
      print(f"{name2}'s strength stats are {strength}")
      character("name", "type")
      os.system("clear")
      print()
      print("Let the battle Begin!!!")
      def ran_side_dice():
      return random.randint()
      def char_health():
      return ran_side_dice() * ran_side_dice() / 2 + 10
      def char_strength():
      return ran_side_dice() * ran_side_dice() / 2 + 12
      def char_damage():
      return ran_side_dice() * ran_side_dice() / 2 + 12
      def return_stats(name1, name2):
      return (f"{name1}'s health is {health1} and strength is {strength1} and {name2}'s health is {health2} and strength is {strength2}")
      while True:
      # Roll one six-sided dice for both characters
      player1_dice = ran_side_dice()
      player2_dice = ran_side_dice()
      # The character who rolls the higher amount wins that round
      if player1_dice > player2_dice:
      print(f"{name1} wins this round!")
      # Take that amount away from the loser's health
      difference = abs(char_strength() - char_strength()) + 1
      health -= difference
      if health player2_dice:
      print(f"{name1} wins this round!")
      # Take that amount away from the loser's health
      difference = abs(char_strength() - char_strength()) + 1
      health -= difference
      if health player1_dice:
      print(f"{name1} loses this round!")
      difference = abs(char_strength() - char_strength()) + 1
      health -= difference
      if health

    • @ayradizem2770
      @ayradizem2770 Před rokem +1

      @@vineetrathod94 I'm just in 17 days then when I will arrived to 28 days I will see your code

  • @matfrei9589
    @matfrei9589 Před 2 měsíci

    # Day 15
    exit=' '
    while exit != 'y':
    print('')
    a = input('What animals do you want? ').lower()
    a=a.strip(" ")
    if a== 'cow':
    print('A cow goes muuuuh.')
    elif a == 'chicken':
    print('A chicken goes tok tok.')
    elif a == 'dog':
    print ('A dog goes Wuff wuff')
    else :
    print(' ')
    print('This animal name is not in my List')
    print(' ')
    exit= input('You want to finish ? y/n :')
    print('*** finished ***')

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

    This is my code for the daily challenge. Am I doing it correctly?:
    animal = ""
    while animal != "cow":
    print("a cow goes moo")
    animal = input("What animal do you want ?: ")
    if animal == "dog":
    print("dog goes woof")
    elif animal == "bird":
    print("chip chip")
    elif animal == "goat":
    print("bah bah")
    else:
    print("have no idea what they sound like!")
    exit == ""
    while exit != "no":
    print("no")
    exit = input("do you want to exit?: ")
    animal = ""
    while animal != "lesser spotted lemur":
    print("Ummm...the Lesser Spotter Lemur goes awooga.")
    animal= input("What animal do you want?: ")
    if animal == "donkey":
    print("hee haw!")
    elif animal == "baboon":
    print("hoot hoot!")
    elif animal == "pig":
    print("oink oink!")
    else:
    print("sorry, can't imitate their noises!")

  • @maissaelkadi6293
    @maissaelkadi6293 Před rokem

    Hi small question 😊. Can someone explain to me why in the first bit of code we write '+=1'? And why simply writing '+1' doesn't work

    • @lara-pn7cq
      @lara-pn7cq Před rokem

      the = is meant to reassign a new value to the counter variable! so you're adding 1 and reassigning the value all in one step with +=1

  • @Acking1.2.0
    @Acking1.2.0 Před 23 dny

    heres mine without the exit
    animal = input("What animal would you like to hear: ")
    if animal == "cow":
    print("MOOO: ")
    if animal == "Cow":
    print("MOOO: ")
    if animal == "Pig":
    print("Oink Oink: ")
    if animal == "pig":
    print("Oink Oink: ")
    if animal == "sheep":
    print("Bheee: ")
    if animal == "Sheep":
    print("Bheee: ")
    if animal == "Horse":
    print("Huuuh huuh: ")
    if animal == "horse":
    print("Bheee: ")
    if animal == "snake":
    print("szzz szzz: ")
    if animal == "Snake":
    print("szzz szzz: ")
    if animal == "Dog":
    print("rugh rugh: ")
    if animal == "dog":
    print("rugh rugh: ")
    if animal == "Cat":
    print("Miao Miao: ")
    if animal == "Cat":
    print("Miao Miao: ")

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

    wrote a nice clean simple code for anyone needing an answer
    exit_game = ''
    while exit_game != 'no': #FIRST setup the exit Parameters
    animal = input ('

    What animal do you want?:')
    if animal == 'cow':
    print ('
    A cow goes MOOOOOO')
    elif animal == 'lemur':
    print ('
    Ummm... a Lemur goes awoooooga')
    elif animal == 'dog':
    print ('
    A dog goes wuff wuff wuff')
    elif animal == 'duck':
    print ('
    A duck goes quackity quack')
    elif animal == 'cat':
    print ('
    A cat goes MEOOOOW')
    else:
    print ('
    I am sorry I do not know what that sound that animal makes
    Please try something different :)!!')
    exit_game = input ('

    Would you like to try another animal?')
    if exit_game == 'no':
    print('Later! Have a great day')

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

    3:25 what happened there?

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

    Well, this one was slightly easier. Although David almost crashed his computer

  • @inhtran3687
    @inhtran3687 Před rokem

    print("\033[32m","WELCOME TO THE ZOO!""\033[0m")
    exit = ""
    while exit != "yes":
    animal = input("Which animal do you choose? We have Dog, Cow, and Cat. ")
    if animal == "Dog":
    print("A dog goes gau gau")
    elif animal == "Cow":
    print("A cow goes moo")
    elif animal == "Cat":
    print("A cat goes meow meow")
    else:
    print("We don't have this animal here")
    exit = input("Do you want to exit? ")
    if exit == "yes":
    print("Bye bye! See you!");

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

    How do I add the emoji in my code like that

    • @ozonehephzibah6949
      @ozonehephzibah6949 Před rokem

      On Windows, hold down your "Windows" key then press full stop key ".", the emoji window will popup

  • @mousammehta
    @mousammehta Před rokem

    I tried 100,000. It took forever to end

  • @manliofaviomascarenosigala3651

    I tried this adding a bit more:
    lista = ["gato","perro"]
    lista_2 = ["Meoow meoow meoow","Woof woof woof"]
    animales = ""
    while animales != lista[0] and animales != lista[1]:
    animales = input("Ingresa un animal para escuchar su sonido: ")
    print()
    if animales == lista[0]:
    print("{}".format(lista_2[0]))
    elif animales == lista[1]:
    print("{}".format(lista_2[1]))
    else:
    print()
    print("El animal {} no se encuentra en el listado, intenta con gato o perro".format(animales))
    print()
    finalizar = ""
    while finalizar != "si" and finalizar != "no":
    print()
    finalizar = input("Deseas finalizar?: ")
    if finalizar == "si":
    print()
    print("Adios!")
    else:
    print()
    finalizar_2=""
    while finalizar_2 != "no" and finalizar_2 !="si":
    finalizar_2 = input("¿Quieres saber algo curioso?")
    print()
    if finalizar_2 == "si":
    print("La base de la física cuántica nos dice que no podemos saber simultáneamente la velocidad y posición de una partícula con precisión. Esto rompe con la idea determinista que todo puede ser predecido. Para ello se realizan varias predicciones y al final se saca una probabilidad de un evento")
    print("Adios!!")
    elif finalizar_2 == "no":
    print("Adioooos!")

    • @nacholaplace9090
      @nacholaplace9090 Před rokem

      consulta el determinismo de laplace, (ta bonito tu código)