Example of a python method with a while loop and args.

Came up with this little diddy. don't know why the Tabs disappeared when I copied it.

Fixed it.   I like doing these,  they help me learn.

def loopyloop(T_or_F, arg, some_number):
print("Method loopyloop is executing.")

while T_or_F:
print(f"This will not run if T_or_F is False.")
print(f"If T_or_F is True, this will run continuously,until I make it False.")
print(f" arguement = {arg} .")

if some_number >= 0:
print("My number is greater then 0. I can change the value,")
print(" of the number in this if block. I can change any of my args.")
print("changing the some_number to make the esle block execute.")
some_number = -1
print("changing the arg in the if block.")
arg = "It's all wibbly wobley timey whimey stuff."
print("I am not changing the T_or_F because I want it to continue running.")


if some_number == -1:
print("second 'if' statement. You can have a million if's, and if every one of them is true, they will all execute.")
some_number = 'Run you clever man.'


elif some_number == 'Run you clever man.':
print("Did this 'elif' execute after I changed the some_number in the if block?")
# it will not execute if the preeceding if blocks ran.

#print("This is changing arg outside of the (if-elif) block")
#arg = "Weeping angels are terrifing."

else:
#else block only runs if all preceeding (if - elif) blocks fail to run
print("Else block is executing.")
arg = "Would you like a jelly belly?"
print("This is outside the if and else, but still inside the while.")
print("While will check at the end to see if my T_or_F is 'True' or 'False'")
print("If I do not make it false, it will run until the system errors out... hopefully.")
print("Are the arguements still changed ?")
print(f"arg = {arg}")
print (f"some_number = {some_number}")
print("Ending the while loop:")
T_or_F = False
print("will this print?")

loopyloop(True, "Matt Smith", 11)

Comments

Popular posts from this blog

JavaScript Ascii animation with while loops and console.log

playing with trigonometry sin in pygame

playing with color in powershell python