How would I code this in the problem below in python? Math Tuple Write a program
ID: 3607733 • Letter: H
Question
How would I code this in the problem below in python?
Math Tuple
Write a program that calculates and prints certain values based on a tuple you create. The program should start with a tuple defining unique numbers.
Then, calculate and print (individually):
1. The average of all of the numbers.
2. The first number in the tuple plus the second.
3. The sum of all the numbers in the tuple.
4. Each number in the tuple multipled by 3.
5. Your answer should these concepts: loops, tuples, math, variables, and anything else to achieve your solution.
Explanation / Answer
t=(1,2,3,4,5,6,7,8,9)
avg=0 # contains average of all of the numbers
sum1=0 # contains sum of all the numbers in the tuple
list=[]
for i in t: # loops through every element of the tuple
sum1+=i #sums up all the element of the tuple
list.append(i*3) #creates new list multiplying by every element of the tuple by 3
print "Sum of all the numbers in the tuple", sum1;
print "average of all the numbers in the tuple", sum1*1.0/len(t);
print "Sum of all the numbers in the tuple multiplied by 3 is", sum(list);
print "The first number in the tuple plus the second is",t[0]+t[1]
print "New tuple created of all the numbers in the first tuple multiplied by 3 is",tuple(list)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.