Python Forum

Full Version: For loop question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, Im new to the community so please correct my first post if needed. Could anyone explain why the result for A occured compared B's result? Visually its obvious but its hard just interpreting it by words. Any help?

A
def main():
   name = input("enter name: ")
   for i in name:
           print(i, end="")
main()


RESULT:
Output:
enter name: francisco francisco
B
def main():
   name = input("enter name: ")
   for i in name:
           print(name, end="")

main()  


RESULT
Output:
enter name: francisco franciscofranciscofranciscofranciscofranciscofranciscofranciscofranciscofrancisco
In your first code, for each letter of the name, you print that letter.
In the second code, for each letter of the name, you print the entire name.