Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loop question
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A question about 'Event loop is closed' fc5igm 2 2,434 Oct-05-2021, 02:00 AM
Last Post: fc5igm
Exclamation question about input, while loop, then print jamie_01 5 2,850 Sep-30-2021, 12:46 PM
Last Post: Underscore
  for loop question KEYS 1 1,823 Oct-27-2020, 11:42 PM
Last Post: jefsummers
  Netmiko Loop question sc00ter 2 3,465 Oct-24-2020, 10:54 PM
Last Post: sc00ter
  while loop question KEYS 2 2,147 Sep-26-2020, 11:02 PM
Last Post: KEYS
  New to programming, loop question tomyan 1 1,780 Sep-25-2020, 04:32 PM
Last Post: Larz60+
  while loop question spalisetty06 2 1,948 Aug-13-2020, 04:18 PM
Last Post: buran
  question about for loop Than999 5 2,668 Jun-09-2020, 02:16 PM
Last Post: Emekadavid
  Question about for loop not creating an infinite loop. FWendeburg 1 2,189 Feb-03-2019, 08:45 PM
Last Post: ichabod801
  Loop Condition Question malonn 6 3,638 Aug-01-2018, 01:56 PM
Last Post: malonn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020