I have to write a program without using list(as I still haven't learnt them) to take 10 names as the input and put them all in lower-case and then capitalize the first letter. I came up with two programs that both work; However, there are some problem! the first programs is:
text=input()
x=text.split()
for name in x:
x=name.lower().capitalize()
print(x)
in the above program I can only take the names in one line and if the user presses enter in order to type the new name in a new line the program would think that the input is over and all. so I searched the internet and found readlines() method but I have no idea how to put a limit to the inputs and I do it manually with "ctrl+z", is there a way I can put a limit to it? the second program is as below:
import sys
text=sys.stdin.readlines()
for esm in text:
x=esm.lower().capitalize()
print(x)
take 10 names as the inputmean? What does the user have to type?text.split()produces a list. So doessys.stdin.readlines().for _ in range(10):If you want the number of names to be chosen by the user who inputs them, you could make an infinite loop that just reads one line and checks if it's empty to break the loop, this way you can finish introducing names by pressing enter twice (which creates an empty line)