Exam 2 Coding Portion Practice

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Build on part B so that you can now ask the user for a specific integer base and an integer exponent. Then display the base raised to that exponent. Your program should function as shown below. Hint: You need to use input, print, and int functions. You might need str function as well depending on how you solve the problem.

-

Create a variable called data and store 10, 20, 30 in it in the order they've listed. Display the result of the following expression each on one line (Hint: use print function to display the result): 1) The expression data[1] evaluates to: 2) The expression data [1:3] evaluate to: 3) The expression data.index(20) evaluates to: 4) The expression data + [40, 50] evaluates to: 5) After the statement data[1] = 5, data evaluates to: 6) After the statement data.insert(1,15), the original data evaluates to: Using comments, please indicated which of these 6 operations changed the original, variable "data" and which ones just use it to output some values (remember list type is a mutable data type and some operations will alter it.) Hint: You can simply print the variable "data" after each expression to see if it has changed.

-

Part B (35 pts): Write a python program that asks the user to enter an integer value and displays the value of 2 raised to that integer. Hint: You need to use input, print, and int functions for part B. You might need str function as well depending on how you solve the problem.

-

Question 1: - Get input from user - You may assume the value is from -100 to 100 - determine if the value is positive, negative, or zero Restrictions: None

-

Question 2: - Give Python code to add up all the elements in a list of integers and displays the result. Partial code which gets the values and stores them into variable nums is provided. - complete the code where it adds up all the values in nums and print the final results

-

Question 3: - Determine the shortest string in a list and print the length of shortest string(s) in the list e.g. 1: names = ['Sunday', 'Monday, 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] prints 6 e.g. 2: names = ['Aria', 'Hannah', 'Amy', 'Tommy', 'Peter'] prints 3

-

Similar to problem 2, write a Python program that prompt the user 3 times to enter an integer value, stores the values in Python list, and display the resulting list (note that all the values in the list must be integer type).

-

Write a Python program that prompt the user 3 times to enter a name, stores the values in Python list, and display the resulting list.

-

Write a Python program that prompt the user to enter a name and store it into a variable called n. The program should display how many times lowercase, character 'a' appears within the name.

-

Write a program that helps the Five Star Retro Video to calculate the total charge. Five Star Retro Video rents VHS tapes and DVDs to the same connoisseurs who like to buy LP record albums. The store rents new videos for $3.00 a night and oldies for $2.00 a night. Write a program that the clerks at Five Star Retro Video can use to calculate the total charge for a customer's video rentals. The program should prompt the user for the number of each type of video and total nights and output the total cost with only two decimal points and with commas where appropriate.

-

Write the python code that allows the user to enter two integer values, and displays the results when each of the following arithme7c operators are applied. 4 + 2 = 6 4 - 2 = 2 4 * 2 = 8 4 / 2 = 2.0 4 // 2 = 2 4 % 2 = 0 4 ** 2 = 16

-

Write the python code that prompts the user for two floating-point values and displays the result of the first number divided by the second, with exactly five decimal places displayed.

-

Write the python code that prompts the user for two floating-point values and displays the result of the first number divided by the second, with exactly six decimal places displayed in scientific notation

-

Write the python code that prompts the user for two integer values and displays the result of the first number divided by the second, with exactly three decimal places displayed.

-


Ensembles d'études connexes

Three Fifths Compromise & Great Compromise

View Set

5. English Grammar Writing Conventions: Colons, Semicolons, and Periods

View Set

Chapter 14 Science cornell notes- The outer planets

View Set

Chp. 24: Microbial Diseases of the Respiratory System

View Set

Chapter 32: Assessment of Hematologic Function and Treatment Modalities

View Set

Alexander Fleming: Discovery of Penicillin

View Set

Lamar University POLS-2302 Test 1 Prof. Terri Davis

View Set