Ask the user to enter a series of 10 numbers separated

Assignment Help Python Programming
Reference no: EM132356936

Answer the following Questions :

Problem 1. What will be the output of the following code?

numbers = [10] * 5

print(numbers)

Problem 2. What will be the output of the following code?

numbers = list(range(1, 20, 2))

print(numbers)

Problem 3. What will be the output of the following code?

numbers = [1, 2, 3, 4, 5]

print(numbers[-2])

Problem 4. What will be the output of the following code?

numbers1 = [1, 2, 3]

numbers2 = [10, 20, 30]

numbers2 += numbers1

print(numbers1)

print(numbers2)

Problem 5. What will be the output of the following code?

numbers = [1, 2, 3, 4, 5]

myList = numbers[:]

print(myList)

Problem 6. What will be the output of the following code?

numbers = [1, 2, 3, 4, 5]

myList = numbers[-3:]

print(myList)

Problem 7. What will be the output of the following code?

names = ['Jim', 'Jill', 'John', 'Jasmine']

if 'Jasmine' not in names:

print('Cannot find Jasmine')

else:

print('Jasmine\'s family:')

print(names)

Problem 8. What will happen if you try to access a list index which is out of range?

a) ValueError exception

b) IndexError exception

c) The list will be erased and the program will continue to run

d) The invalid index will be ignored and the program will continue to run

Problem 9. Assume the following statement appears in a program:

myList = [ ]

Which of the following statements should you use to add the string Labrador to the list at index 0?

a) myList[0] = 'Labrador'

b) myList.insert(0, 'Labrador')

c) myList.append('Labrador')

d) myList.insert('Labrador', 0)

Problem 10. Given lst = [30, 1, 2, 1, 0], what will lst look like after applying each of the following statements? Assume each line of code to be independent.

a) lst.append(40)

b) lst.insert(1, 43)

c) lst.extend([1, 43])

d) lst.remove(1)

e) lst.pop(1)

f) lst.pop()

g) lst.sort()

h) lst.reverse()

i) random.shuffle(lst)

Problem 11. Given lst = [30, 1, 2, 1, 0], what is the return value for each of the following statements? Assume each line of code to be independent.

a) lst.index(1)

b) lst.count()

c) len(lst)

d) max(lst)

e) min(lst)

f) sum(lst)

Problem 12. What will be the list for each of the following statements?

a) [x for x in lst if x > 1] # Assume lst = [30, 1, 2, 1, 0]

b) [x for x in range(0, 10, 2)]

c) [x for x in range(10, 0, -2)]

Problem 13. Given list1 = [30, 1, 2, 1, 0] and list2 = [1, 21, 13], what will the following statements evaluate to?

a) list1 < list2

b) list1 <= list2

c) list1 == list2

d) list1 != list2

e) list1 > list2

f) list1 >= list2

Problem 14. Ask the user to enter a store's sales for each day of the week. Use a loop to store the amounts in a list. Use a loop to calculate the total sales for the week and display the result. [Note: You are not allowed to use the sum() function.]

Sample program output:

Enter sales for day 1: 2000

Enter sales for day 2: 1000

Enter sales for day 3: 2500

Enter sales for day 4: 3400

Enter sales for day 5: 4600

Enter sales for day 6: 1100

Enter sales for day 7: 2200

Total sales for the week: 16800

Problem 15. Ask the user to enter a series of 10 numbersseparated by space. The program should store the numbers in a list and then display the following:

• The lowest number in the list

• The highest number in the list

• The total of the numbers in the list

• The average of the numbers in the list

[Note: You may make use of inbuilt functions.]

Sample program output:

Enter 10 numbers (separate by space): 21 54 77 10 34 45 91 66 2 12

Lowest: 2

Highest: 91

Total: 412

Average: 41.2

Problem 16. Write a python script to check whether a list is already sorted in decreasing order or not.

Sample program output I:

Enter some numbers: 3 2 1 4 5 6

The list is not sorted

Sample program output II:

Enter some numbers: 45 34 23 4

The list is sorted

Problem 17. Ask the user to enter his first name and surname on a single line. Save the first name and surname in a list and print out the list. Ask the user to enter middle name. Insert the middle name in the list in the proper position and print the list again.

Sample program output:

Enter first name and surname: Harry Potter

[‘Harry', ‘Potter']

Enter middle name: James

[‘Harry', ‘James', ‘Potter']

Problem 18. Write a python script to generate 1000 random digits (0 - 9) and display the count for each digit.

[Hint: Use a list of size 10 initialized to all 0s, where each index corresponds to the digit, and update the counts of the digits accordingly.]

Sample program output:

0: 108

1: 113

2: 98

3: 98

4: 100

5: 96

6: 91

7: 95

8: 106

9: 95

Problem 19 (Extra credit). Write a python script to enter a string of characters (without any whitespace, but can include digits). Print out a list of the distinct letters from the entered string.

[Hint: Start with an empty list. Read each character from the string and add it to the list only if it is a letter (read up on isalpha()), and it is not in the list.]

Sample program output:

Enter a string: abBA113av6

The distinct letters are [‘a', ‘b', ‘B', ‘A', ‘v']

Reference no: EM132356936

Questions Cloud

Role and impact forensic anthropology has on death : Write a scholarly paper critically evaluating the role and impact Forensic Anthropology has on death investigations - summarizing the science of Forensic
What are the criteria that need to be included : What are the criteria that need to be included in negotiation contract to make it valid? Please provide the reference/ source of the informaton.
Existence is the increase shareholder wealth : Since a corporations only reason for existence is the increase shareholder wealth, is it really possible, or should it even be, for it be a "good corporate
Why are standard operating procedures : Why are Standard Operating Procedures an effective way to communicate?
Ask the user to enter a series of 10 numbers separated : CMPSC 101 Introduction to Programming in Python- Ask the user to enter a store's sales for each day of the week. Use a loop to store the amounts in a list.
Explain which perspectives : Explain which perspectives, definitions, and focus areas would be most relevant for your situation.
Manage a furniture warehouse and distribution : Assume you manage a furniture warehouse and distribution center. Explain which perspectives, definitions, and focus areas would be most relevant
How research questions or hypotheses relate to qualitative : How research questions or hypotheses relate to qualitative, quantitative, or mixed methods approach?
What is industrial tour report : What is Industrial tour report? I want some sample copy of for learning that.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd