Computer Science
Write programs as per following specifications:
'''L is a list of numbers. Print a new list where each element is the corresponding element of list L summed with number num.'''
Python
Python List Manipulation
9 Likes
Answer
l1 = eval(input("Enter list of numbers: "))
num = int(input("Enter the number to sum with (num): "))
l2 = []
for i in l1:
l2.append(i + num)
print("New list:")
print(l2)
Output
Enter list of numbers: [10, 20, 30, 40, 50]
Enter the number to sum with (num): 15
New list:
[25, 35, 45, 55, 65]
Answered By
5 Likes
Related Questions
Write a program that reads the n to display nth term of Fibonacci series.
The Fibonacci sequence works as follows:
- element 0 has the value 0
- element 1 has the value 1
- every element after that has the value of the sum of the two preceding elements
The beginning of the sequence looks like:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …The program prompts for element and prints out the value of that element of the Fibonacci sequence.
Thus:
- input 7, produces 13
- input 9, produces 34
Hints:
A Don't try to just type out the entire list. It gets big very fast. Element 25 is 75205. Element 100 is 354224848179261915075. So keep upper limit of n to 20.Write programs as per following specifications:
'''Print the length of the longest
string in the list of strings str_list.
Precondition : the list will contain
at least one element.'''Write a program to read two lists num and denum which contain the numerators and denominators of same fractions at the respective indexes. Then display the smallest fraction along with its index.
Write a program to display the maximum and minimum values from the specified range of indexes of list.