Q. Write a program to increment the elements of a list with a number.
Answer =
lst = [ ] while True : num = int(input("Enter a number :- ")) lst.append(num) user = input("Do you want to quit enter yes =") if user == "yes": print(lst) break
Output :-
Enter a number :- 2
Do you want to quit enter yes =no
Enter a number :- 5
Do you want to quit enter yes =no
Enter a number :- 7
Do you want to quit enter yes =no
Enter a number :- 9
Do you want to quit enter yes =no
Enter a number :- 6
Do you want to quit enter yes =no
Enter a number :- 2
Do you want to quit enter yes =yes
[2, 5, 7, 9, 6, 2]
>>>
Output?
ReplyDeleteOk. I have written it.
Deletelst = [ ]
ReplyDeletewhile True :
num = int(input("Enter a number :- "))
lst.append(num)
user = input("Do you want to quit enter yes =")
if user == "yes":
print(lst)
break
Output :-
Enter a number :- 2
Do you want to quit enter yes =no
Enter a number :- 5
Do you want to quit enter yes =no
Enter a number :- 7
Do you want to quit enter yes =no
Enter a number :- 9
Do you want to quit enter yes =no
Enter a number :- 6
Do you want to quit enter yes =no
Enter a number :- 2
Do you want to quit enter yes =yes
[2, 5, 7, 9, 6, 2]
>>>
Hi
ReplyDeletewrong program
ReplyDeletel=[int(i) for i in input().split()]
ReplyDeleten=int(input())
l1=l.copy()
for i in range(len(l)):
l[i]+=n
print("original list=",l1)
print("modified list=",l)
THIS IS THE CORRECT CODE
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )