Skip to content
Sign upLog in
← Back to Community

How do I add a loop to this?

Profile icon
Archanakumar13

I have written a code using conditional statements. But, I need to run it on a loop. For example, if I input Today is: Monday and it prints the statement 'I am having the Monday blues again! How long till it is Friday?'.

How do I get it to keep running the code so that it keeps repeating the input Today is: ?

Can someone please clarify this for me?

Voters
Profile icon
Jackolanternexe
Comments
hotnewtop
Profile icon
Jackolanternexe

I guess try something like this:

if dayOfWeek == monday: print("I am having the Monday blues again! How long till it is Friday?")

I dunno if this will help or not, if not try to be more specific?


@Archanakumar13

Profile icon
Archanakumar13

@Jackolanternexe
Hi! I found the correct way with
@Kopamed
's help! Thank you though! :)

Profile icon
Kopamed
while True: answer = input("What day is it today") if answer.lower() == "monday": print("Oh boy is it monday") #if this is your expected output than add break break elif answer.lower() == "tuesday": print("Not as bad as monday....")
Profile icon
[deleted]

@Kopamed
Don't just give him the code. At least try to explain it! :)

Profile icon
Kopamed

@johno1566
@Archanakumar13
The code eill repeat that code until it hits break

Profile icon
Archanakumar13

@Kopamed
Hey! Thank you! This worked! Can you please explain the first and second line? How does the first line (while True:) solve the problem? Also, what does the answer.lower function do exactly

Profile icon
Archanakumar13

@Kopamed
This is very helpful! Thank you! :)

Profile icon
Kopamed

@Archanakumar13
while True just makes sure that asll the code indented below it runbs forever until it hits a break sttement when it breaks. The .lower() makes all the letters in a string lowercase

while True: print("I will run forever!")
string = "HELLO" print(string) print(string.lower())

HELLO
hello

Profile icon
Archanakumar13

@Kopamed
Thank you!

Profile icon
Kopamed

@Archanakumar13
Welcome! :)

Profile icon
ash15khng

You can do while today != "monday": then add the rest of the code.

Profile icon
Archanakumar13

@ash15khng
Thank you! :)

Profile icon
Archanakumar13

@ash15khng
I found the correct way with
@Kopamed
's help :)