In: Computer Science
hi i need a code that will give me this output,
For the multiply_list, the user will be asked to input the length of the list, then to input each element of the list.
For the repeat_tuple, the user is only asked to enter the repetition factor, but not the tuple. Your program should take the list created before and convert it to a tuple.
output expected: (**user input**)
******Create your List ******
Enter length of your list: 3
****** Start filling your List ******
Enter element 1: 2
Enter element 2: 3
Enter element 3: 4
Result of list multiplication: 24
*** Create a tuple and repeat it
Enter your repetition factor: 2
Repeated Tuple: (2, 3, 4, 2, 3, 4)
this is what i have so far:
print("\n********* Create Your List ********") len_list = int(input("Enter length of your list: ")) print("\n********* Start filling your list ********") if len_list > 0: element = int(input("Enter element {0}: ".format(len_list)))
print("***create your list***")
lenght_of_list = int(input("Enter Length of your list: "))
l = []
multiplication_result = 1
for i in range(lenght_of_list):
l.append(int(input("Enter element "+str(i+1)+" ")))
multiplication_result = multiplication_result*l[i]
print("Result of list multiplication : "+ str(multiplication_result))
def convert(list):
return (*list,)
print("***create a tuple and repeat it ***")
tup = convert(l)
repetation_factor = int(input("Enter your repetation factor : "))
print(tup*repetation_factor)
Code:
print("***create your list***") lenght_of_list = int(input("Enter Length of your list: ")) l = [] multiplication_result = 1 for i in range(lenght_of_list): l.append(int(input("Enter element "+str(i+1)+" "))) multiplication_result = multiplication_result*l[i] print("Result of list multiplication : "+ str(multiplication_result)) def convert(list): return (*list,) print("***create a tuple and repeat it ***") tup = convert(l) repetation_factor = int(input("Enter your repetation factor : ")) print(tup*repetation_factor)
Result: