Python Mid-Term

¡Supera tus tareas y exámenes ahora con Quizwiz!

1. Identify the data type for the following data.

a. 1 (Integer) b. '1' (String) c. [1, 2, 3] (List) d. ['1', '2', '3'] (List) e. '[1, 2, 3]' (String) f. {1: 5, 2: 8} (Dictionary) g. {'1': 5, '2': 8} (Dictionary) h. '{1: 5, 2: 8}' (String)

1. The book price is 8.99 and the tax rate is 7%, calculate the final payment and round the amount to cents saved in the variable v_payment.

book_price= 8.99 tax_rate=1.07 v_payment = book_price*tax_rate v_payment=round(v_payment,2) print(v_payment) 9.62

1. The product code is "38BEE27". Get the first two characters for its industry code saved in the variable v_industry_code, and the third character for its class type saved in the variable v_class_type.

product_code= '38BEE27' v_industry_code = product_code[:2] print(v_industry_code) 38 v_class_type= product_code[2] print(v_class_type) B

1. You need to calculate the sale price after discount for each item in the following dictionary variables. v_original_price = {"Book": 87, "Computer": 76, "Apple": 65} v_discount_rate = {"Apple": 0.1, "Computer": 0.2, "Book": 0.3}

v_original_price = {"Book": 87, "Computer": 76, "Apple": 65} v_discount_rate = {"Apple": 0.1, "Computer": 0.2, "Book": 0.3} salesprice_book = v_original_price["Book"]-(v_original_price["Book"]*(v_discount_rate ["Book"])) salesprice_computer = v_original_price["Computer"]-(v_original_price["Computer"]*(v_discount_rate ["Computer"])) salesprice_apple =v_original_price["Apple"]-(v_original_price["Apple"]*(v_discount_rate ["Apple"])) print(salesprice_book, salesprice_computer, salesprice_apple) 60.900000000000006 60.8 58.5

1. Download the following transaction data https://www.dropbox.com/s/k97psmvvom8p8jl/supermarket.csv?dl=0. This data has the information for each purchased item with its "Date, Transaction Number, UPC Number, Product Name, Customer Account, Qty, Regular Price, Sale Price, and Discount". Please write the python code to show the Date, Transaction Number, UPC Number, Customer Account, and Sale Price for the 2000000th records.

v_supermarket_file = open('data/supermarket.csv') v_super = supermarket_file.readlines() Date = v_super[2000001].split(',')[0] Transaction_Number = v_super[2000001].split(',')[1] UPC_Number = v_super[2000001].split(',')[2] Customer_Account = v_super[2000001].split(',')[4] Sales_Price= v_super[2000001].split(',')[7] Print (Date , Transaction_Number , UPC_Number, Customer_Account, Sales_Price)

BMI for a person is calculated as weight in kg / (height in meters * height in meters). You need to calculate everyone in the following list variables v_weight = [65, 87, 76] v_height = [1.67, 1.83, 1.76]

v_weight = [65, 87, 76] v_height = [1.67, 1.83, 1.76] bmi_1 = v_weight[0]/(v_height[0]*v_height[0]) bmi_2= v_weight[1]/(v_height[1]*v_height[1]) bmi_3= v_weight[2]/(v_height[2]*v_height[2]) print(bmi_1,bmi_2,bmi_3) 23.306680053067517 25.97867956642479 24.535123966942148

1. BMI for a person is calculated as weight in kg / (height in meters * height in meters). You need to calculate everyone in the following list variables. v_weight = [65, 87, 76] v_height = [1.67, 1.83, 1.76]

v_weight = [65, 87, 76] v_height = [1.67, 1.83, 1.76] for i in range(len(v_height)): print(v_weight[i] / (v_height[i] * v_height[i])) 23.306680053067517 25.97867956642479 24.535123966942148

1. BMI for a person is calculated as weight in kg / (height in meters * height in meters). You need to calculate everyone in the following dictionary variables. v_weight = {"Bob": 87, "Cindy": 76, "Alice": 65} v_height = {"Alice": 1.67, "Cindy": 1.76, "Bob": 1.83}

v_weight = {"Bob": 87, "Cindy": 76, "Alice": 65} v_height = {"Alice": 1.67, "Cindy": 1.76, "Bob": 1.83} for k, v in v_weight.items() : print(k, "->", v / (v_height[k] * v_height[k])) Bob -> 25.97867956642479 Cindy -> 24.535123966942148 Alice -> 23.306680053067517

1. BMI function for a person is calculated as weight in kg / (height in meters * height in meters). For Bob, his weight is 60kg, and height is 1.7m. Calculate his BMI saved in the variable v_bmi. weight= 60 height=1.7

weight= 60 height=1.7 v_bmi= weight/(height*height) print(v_bmi) 20.761245674740486


Conjuntos de estudio relacionados

AWS Certified Solutions Architect - Associate Practice Questions

View Set

Evolutionary bio - Gamble: Ch. 14

View Set

Network+ 8th edition, Chapter 1 review questions

View Set

AP Statistics TPS4e Chapter 6 Random Variables Vocabulary

View Set

History Chapter 4 Test Study Guide

View Set

HIST 140 Lecture 17 Smoking, Lung Cancer, and Discovery of risk

View Set

Exercise 32 Review Sheet : Anatomy of Blood Vessels (A&P)

View Set

Metabolic Elimination Passpoint quizz

View Set

Literary Terms for Year One Eng. Lit BA(hons)

View Set