1)use two list one for names and one for cost 2) keep total cost you will spend and print the average cost for a gift - ????? could you do this with just one list??? 3) after end of loop print the two list and the average and the number of name and number of cost in the list. (suggestion - use for loop) USE this Program: Holiday = [] name = input("enter name").upper() while name != "XXX": cost = float(input("enter amount to spend >0 and <=10")) while cost <=0 or cost >10: print("invalid cost") cost = float(input("enter amount to spend >0 and <=10")) gift = name + " " + str(cost) Holiday.append(name) Holiday.append(cost) Holiday.append(gift) name = input("enter name").upper() print(Holiday)
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
USE this Program:
Holiday = []
name = input("enter name").upper()
while name != "XXX":
cost = float(input("enter amount to spend >0 and <=10"))
while cost <=0 or cost >10:
print("invalid cost")
cost = float(input("enter amount to spend >0 and <=10"))
gift = name + " " + str(cost)
Holiday.append(name)
Holiday.append(cost)
Holiday.append(gift)
name = input("enter name").upper()
print(Holiday)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images