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]

>>>

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. 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]

    >>>

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post