1) Python statement to define a list
Statement:
temps=[95,100,77,54,103,82]
Screenshot of the code:
![1 2 temps=[95,100,77,54,103,82]](http://img.homeworklib.com/questions/19a88130-de20-11ea-9f11-4f34ed750466.png?x-oss-process=image/resize,w_560)
2)length of the list temps
The length of the list temps is 6.
Code:
temps=[95,100,77,54,103,82]
length=len(temps)
print(length)
Screenshot of the code:
![1 2 3 4 temps=[95,100,77,54,103,82] length=len(temps) print(length)](http://img.homeworklib.com/questions/1a048a20-de20-11ea-ba3e-d5cb4ce52fa7.png?x-oss-process=image/resize,w_560)
Screenshot of the output:
3)index position value of 77
Code:
temps=[95,100,77,54,103,82]
#finding index
i=temps.index(77)
print(i)
Screenshot of the code:
Screenshot of the output:
Index position value of 77 is
2.
4)Output of print(temps)
print(temps) will display the list temps
Code:
temps=[95,100,77,54,103,82]
print(temps)
Screenshot of the code:
Screenshot of the output:
5) Show output of
print(temps[3])
It displays the element which is present at index position 3.
Code:
temps=[95,100,77,54,103,82]
i=temps[3]
print(i)
Screenshot of the code:
Screenshot of the output:
The value at index position 3 is
54.
6) Output of print(temps[2:5])
It displays the elements from index position 2 to (5-1) that is 2 to 4
Code:
temps=[95,100,77,54,103,82]
print(temps[2:5])
Screenshot of the code:
Screenshot of the output:
7) statement to add another
temperature at the end of the list
temps=[95,100,77,54,103,82]
#adding value at the end of the list
temps.append(39)
#printing the list
print(temps)
Screenshot of the code:
Screenshot of the output:
8) for loop to print the
list:
Code:
temps=[95,100,77,54,103,82]
for i in temps:
print(i)
Screenshot of the code:
![1 2 3 4 temps=[95,100,77,54,103,82] for i in temps: print(i)](http://img.homeworklib.com/questions/1e14efd0-de20-11ea-bb6f-2feb5f3dfd13.png?x-oss-process=image/resize,w_560)
Screenshot of the output:
![In [10]: runfile(C:/Users/Sandhya/Spyder programs/s.py, wdir=C:/Users/Sandhya/Spyder programs) 95 100 77 54 103 82](http://img.homeworklib.com/questions/1e67b990-de20-11ea-b5ff-01ab69408c5f.png?x-oss-process=image/resize,w_560)
9) using iteration dispaly the temp>100
Code:
temps=[95,100,77,54,103,82]
for i in temps:
if(i>100):
print(i)
Screenshot of the code:
![1 2 3 4. 5 temps=[95,100,77,54,103,82] for i in temps: if(i>100): print(i)](http://img.homeworklib.com/questions/1ebf48a0-de20-11ea-8e61-010e29d2a997.png?x-oss-process=image/resize,w_560)
Screenshot of the output:
10) avg of the values in
temp
temps=[95,100,77,54,103,82]
#finding the length of the list
n=len(temps)
sum=0
#for loop to find the sum pf all values
for i in temps:
sum=sum+i
#finding the average
avg=sum/n
#displaying average
print(avg)
Screenshot of the code:
Screenshot of the output:
11) Trace when the user inputs a
value of 5.
Code:
reps=int(input("Enter the number of times you want to display Meteors!"))
n=2
while n<reps:
print("Meteors!")
n=n+1
Tracing:
n=2, reps=5
The code in the while loop executes when n<reps
i)n=2,reps=5
while(2<5):
The condition is true . So print Meteors!
n=n+1
n=2+1
n=3
ii)
n=3,reps=5
while(3<5):
The condition is true . So print Meteors!
n=n+1
n=3+1
n=4
iii)
n=4,reps=5
while(4<5):
The condition is true . So print Meteors!
n=n+1
n=4+1
n=5
iv)
n=5,reps=5
while(5<5):
The condition is false. So while loop is terminated.
The word is printed 3 times
12) MCQ
The underlined expression in red is Loop Continuation test.
It checks whether the loop to be continued or stopped.
If the expression is true then the loop continues .
If the expression is false then the loop stops or terminates
13) for loop to define list:
Code:
temps=[i for i in (95,100,77,54,103,82)]
print(temps)
Screenshot of the code:
Screenshot of the output:
14)Answer:
We can't say how many times the loop repeats. I will repeat until the entered is greater than or equal to 20.
When the value is greater than or equal to 20 the loop stops.
(Write or type in answers, except for problem #15, which should be entered as a small...
Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that uses iteration to guess a number from 1 to 10. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) a screenshot of the output, and 3) the Python program. Instructions Write pseudocode for a Python program that uses iteration to guess a number from...
in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){ sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() { int score, highest; //missing portion of the program return 0; } 1(c). Find the missing portion of the following code, so the...
21 Write a program that asks the user to input the length and breadth of a soccer field, and then computes and returns the number of square meters of grass required to cover the field The formula for the area is the product of length and breadth (5) 22 The following program uses the break statement to terminate an infinite while loop to print 5 numbers Rewrite the program to use a while loop to display numbers from 1 to...
Note: You must write this program in Python. General Requirements The program should display a menu and allow the user to perform one of the following tasks. Add an item to the list Delete an item from the list Print the list Print the list in reverse Quit the program The program should run until the user chooses to quit. In Python, programmatically quitting the application is achieved with the exit() procedure. You should use a List to store the...
Write the code in Python. The output should be exact the same as
the given.
Question 1. Study the examples below carefully and write a program for journal subscription Your program should work exactly as the following examples The text in bold indicates user input. Example 1: The user is a student, and the user subscribes to 2 journals Question 1 - Journal of Commodity Markets Journal of Sustainable Mining Journal of Asia-Pacific Biodiversity Student $21 $22 $27 Non-student $50...
Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() : new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...
I need help with a C++ assignment: Write a program containing the following: 1. Variable Definitions only as (DieRoll, Guess, cnt1, cnt2) followed by this statement: srand((unsigned int)time (NULL)); which will give the random number generator a random starting point. Note: srand and rand require the TIME.H (or iomanip) cnt1 and cnt2 will be used in Chapter 5 drop box as counters for loops. Do NOT create additional variables. Points will be taken off for any additional variable creation. 2....
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
Consider the following function with a real variable, x: ?(?) = ?3 - 3?2 + 6? + 10 a. Write a Python function for the derivative of f(x) that takes x and returns the derivative of f(x). Take the derivative of f(x) analytically with respect to x before writing the function. b. Write a Python code that approximately finds the real root, x0, of f(x) such that f(x0)~0 using the Newton-Raphson method. The code is expected to get an initial...
Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....