Question: Q1: Write a python code using if- if else - else statement to calculate a tip based on the amount of a restaurant bill using

 Q1: Write a python code using if- if else - elsestatement to calculate a tip based on the amount of a restaurantbill using the following rules: 1. Bill less than 10 QR Tipis 1.80 2. Bill between 10 and 60 QR Tip is %183. Bill above 60 QR Tip is %20 Hint: Use input fuctionto get the bill value from the user ? In [ ]:

Q1: Write a python code using if- if else - else statement to calculate a tip based on the amount of a restaurant bill using the following rules: 1. Bill less than 10 QR Tip is 1.80 2. Bill between 10 and 60 QR Tip is %18 3. Bill above 60 QR Tip is %20 Hint: Use input fuction to get the bill value from the user ? In [ ]: 1 ## new program 2. 3 Q2: Write a Python code Using a while loop to determine how many terms in the series 2^k, for k= 1, 2, 3,... are needed for the sum of terms to exceed 2000. Display the sum for this number and the value of k. In [ ]: 1 ### new program 2 3 Q3 Write a Python code using while/for loop to find max list element Without using built in functions in python. numlist = [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] In [ ]: 1 ### using for loop 2 numlist = [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] In [ ]: 1 ### using while loop numlist = [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] 2 Q4: Write a new function removezeros that removes the zeros from any given list of numbers, and returns a list with all zeros removed. The returned list preserves the original order of the non-zero numbers. You may use a for loop or a while loop. In [ ]: def removezeros (nums): removes zeros from input list nums and returns a list II II 11 11 11 11 UiA W NP. nozeros [] for r in nums : != 0: nozeros.append(r) if r OOO return(nozeros) 9 10 Q5: apply the function to the following lists 1. numlist = [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] 2. zz = [0,0,0,0,0] In [ ] : 1 ### new program 2 numlist = [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] 3 4 nz = removezeros (numlist) 5 print(nz) 6 #print(removezeros(numlist)) Part 2: User Defined Functions Q4: Write a new function removezeros that removes the zeros from any given list of numbers, and returns a list with all zeros removed. The returned list preserves the original order of the non-zero numbers. You may use a for loop or a while loop. In [ ]: def removezeros (nums): removes zeros from input list nums and returns a list II II II 11 11 11 1 2 3 4 5 6 7 nozeros [] for r in nums : if r != 0: noze s. 5. append(r) 8 return(nozeros) 9 10 Q5: apply the function to the following lists 1. numlist = [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] [0,0,0,0,0] 2. ZZ = In [ ]: -4, 0, -2, 7, -1] 1 ### new program 2 numlist [2, -4, 0, 0, -1, 5, 2, 3 4 nz = removezeros(numlist) 5 print(nz) 6 #print(removezeros(numlist)) In [ ]: 1 ZZ = [0,0,0,0,0] 2 print(removezeros(22)) Q6: Write a new function rzeros that removes the zeros from any given list of numbers, and returns a list with all zeros removed as well the number of zero entries in the list and non-zero entries in the list. The returned list preserves the original order of the non-zero numbers. For example, given the list numlist = the tuple [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] , your function should return ([2, -4, -1, 5, 2, -4, -2, 7, -1], 9, 3) In [ ]: 1 2 def rzeros(nums): removes zeros from input list nums and returns a list Q7: apply rzeros to the following lists 1. numlist = [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] 2. zz = [0,0,0,0,0] In [ ]: [2, -4, 0, 0, -1, 5, 2, -4, 0, -2, 7, -1] 1 numlist 2 3 In [ ]: 1 ZZ [0,0,0, 0, 0] 2 Q8: Write a new function multiplyList that multiply all values in the list. In [ ]: 1 # Python program to multiply all values in the list. 2 3 4 5 Q9: apply the function to the following lists = 1. numlist1 [1,2, 3,7] 2. numlist2 = [10,5,2,3]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!