Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
26 views
1 Intro To Python Solutions
Uploaded by
sheetalchandra2004
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 1 Intro to Python Solutions For Later
Download
Save
Save 1 Intro to Python Solutions For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
26 views
1 Intro To Python Solutions
Uploaded by
sheetalchandra2004
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 1 Intro to Python Solutions For Later
Carousel Previous
Carousel Next
Save
Save 1 Intro to Python Solutions For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 4
Search
Fullscreen
1 Introducing Python - solutions to exercises Table of Contents > [Llneoducing Python - solutions to exercises ‘Li Peining on LLL Adding Dexibilty © 1.2 Finding the area ofa rstanele 121 Adding fexibilsy ais 14 Basie Arithmetic LI. Printing on sereen Ccreatea function named show_address that will display your name and your mailing aess, The funtion doesnot need to take any addtional info or return anything, Therefore you may just call it ike -show_address() and it should print on screen something like: your name street name and suburb postcode and city country “The function will have empty parameter list and will not have the return. statment. I [1] 1 def show_address(): 2 print('Jon Snow) 3 print (‘Mystery Road, IceTree") 4 print ('1235, Pentos") 5 print (*westeros") In [2]: 1. show_address() Jon Snow Mystery Road, TceTree 1235, Pentos westeros 1.1.1 Adding flexibility Modify you previous solution so that show_address accepts additional information, the ame ofthe person to print the addess. For example, when you call it show_adéress("Janes Cook" ) it will printout James Cook name followed by your adress. In [3] 1 deF show_address(name, street, suburb, postcode, city, country): 2 print(nane) 3 print(street, suburb) 4 print (postcode, city) 5 print(eountry)In [4] 1 show_address(*Jack Snell", ‘West Ave.", "Kingswood", °2231', ‘Silver City’, ‘Greenland') Jack Snell West Ave. Kingswood 3231 Silver city Greenland In [5]: 1 show_address(*Andy Shark’, "South Ave.', "Woodside’, 1231", "Iced City’, "Redland" ) Andy Share South ave, Woodside 1231 Iced city Redland 1.2 Finding the area of a rectangle Write function #ind_area that asks the user to enter the wid and length ofa rectangular room, Once these values have been read, your program should compute and display the area ofthe room, The length and the width will be entered as leating-point numbers. Include units n your prompt and output message. Calling the function by name Find_area() should produce the message like: ‘The area of your room is 24.4 square metres. Ofcourse, the actual number wil differ for your toom, In [6] 1 def Find area() # Read the width and height of the room floor width = float(input(‘Enter width of the room: *)) height = Float(input("Enter height of the room: ")) ropply formula (known from school) for area of a reactangle area = width * height print out/display the output print('The area of the room is ¥.1f square metres.” Xarea) In 7}: 1. #ind_area() Enter width of the roon: 3 Enter height of the room: 4.2 ‘The area of the room is 12.6 square metres. In [8]: 1 det Find_area(nane) 2 width = float(input(*Enter width of the room: *)) 3 height = Float(input ("Enter height of the room: ")) 4 area = width * height 5 print("The area of your room Xs is %.1# square metres.’ ¥(name,area)) In [3] 4 find_area(‘Julie') Enter width of the reon: 4.6 Enter height of the room: 2.4 ‘The area of your room Julie is 11.0 square eetres.1.2.1 Adding flexi ity “Modify you previous solution to find she volume ofa room and not asking the user for input. Instead, the requited input willbe passed to the function through arguments. Cal the function Find_volume . It will accept four pieces of additional infrmation: person's name, loor_width, floor height, and room_ height For exarmple, when you call it find_volume(*Julie', 5, 3.21, 2.7) iwill printout The voluse of your room Julie is 43.36 cubic metres. [Note that you donot ned to eal the required information using. Input. function, In [10] 1 def Find_voluse(nane, floor_width, floor_height, room_height): 2 valune = floor_width * floor. height*roon_hesgnt 3 print (‘The volume of your roan 5 is ¥.1f cubic metres.’ X(nane, volune)) I [11] A #ind_volume(Julie', 5, 3.21, 2.7) ‘The volune of your roon Julie is 43.3 cubic retres. 1.3 Free fall Given the height from which the objec is dropped in metes, write a function named free_fal1_speed that determines how quickly an objet is traveling when ithits the ground, Assume the objec’ inital speed is ey and the acceleration due to gravity is constant a = 9.8m (as you iat intl reall fom shoo), You can use the formula v = fof + 2ad to compat th inal velocity, when he intl speed yy and distance, dre known. You may either ask the user for input of 1» and dor pass this info tothe function when you call ike free_fall_speed(1@, 20) For practice you may as well provide both implementations, Printout the answer with 3 decimal laces, Ta calculate the square rot use the sport statement io enable sant function from math import sqrt Im [12] def free_f011_speed(ini_speed, distance) from math import sqrt # befine a constant for the acceleration due to gravity in m/s**2 GRAVITY = 9.8 # Compute the final velocity vf = sqrt(ini_speed**2 + 2 * GRAVITY * distance) # Display the result print("Tt will hit the ground at ¥.2f m/s." % vf) a 2 3 4 5 6 7 8 ° 2 2 ay [13] 1. free_fal1_speed(19,20) It will hit the ground at 22.18 m/s. allematvely,you could ask for user for al (or some) input valuesIn [34] 1 def Free_fall_speed2(ini_speed): 2 from math inport sqrt a 4 # Define a constant for the acceleration due to gravity in m/s**2 5 GRaviTy = 9.8 7 Read the height from which the object is dropped B distance = Floatinput("Enter height (in seters): ")) 9 10 Compute the final velocity 11 vf = sqrt(ini_speed**2 + 2 * GRAVITY * distance) 2 13 # Display the result 14 print(*rt will hit the ground at %.2F m/s." X vf) 1s 1n [25] 1. free_fall_speed2(10) Enter height (in meters): 12.7 Tt will hit the ground at 18.68 m/s. 1.4 Ba Create a funetion that reads two integers, x and y, ftom the usr. It should compute and display the sum x + y, difference x — y, product x « y, quotient xy and the power 7 Arithmetic In [36] 1 def arithnetic(): 2" # Read the input values from the user 3 x= tntCinpus("Enter the value of x: ")) 4 y= ineCinpus(’Enter the value of y: ")) 5 # Compute and display the sun, difference, product, quotient and power © print(x, “="s ys ‘iss x #y) 7 print Qe *="5 ys Tis" x = ¥) 8 print, 5 ys 38s x ty) 9 print, “3 ys 38) x Ly) 18 printOxs "1, ys "is', xy) an [37] 2 arsthmetie() Enter the value of x: 5 Enter the value of y: 7 S+7 isa Tis -2 7 is 35 7 is 0.7102857142857143, 7 As 78125
You might also like
Python
PDF
No ratings yet
Python
5 pages
Programming and Problem Solving Through Python
PDF
No ratings yet
Programming and Problem Solving Through Python
245 pages
Think Python - Answers - Wikibooks, Open Books For An Open World
PDF
No ratings yet
Think Python - Answers - Wikibooks, Open Books For An Open World
27 pages
Think Python/Answers
PDF
No ratings yet
Think Python/Answers
10 pages
ITC - Functions and Files
PDF
No ratings yet
ITC - Functions and Files
77 pages
Python .g3g3
PDF
No ratings yet
Python .g3g3
13 pages
Aaaa
PDF
No ratings yet
Aaaa
17 pages
Exercise 02.1.1-Extra
PDF
No ratings yet
Exercise 02.1.1-Extra
4 pages
1.fahrenheit To Celsius and Vice Versa Conversion
PDF
No ratings yet
1.fahrenheit To Celsius and Vice Versa Conversion
22 pages
Assignmentm
PDF
No ratings yet
Assignmentm
27 pages
Geografía
PDF
No ratings yet
Geografía
2 pages
Python Main Programs Set 1
PDF
No ratings yet
Python Main Programs Set 1
10 pages
Assignment-1 Solutions
PDF
No ratings yet
Assignment-1 Solutions
3 pages
IP Programs
PDF
No ratings yet
IP Programs
15 pages
Introduction To Python Solutions
PDF
No ratings yet
Introduction To Python Solutions
36 pages
Lab Manual For Python
PDF
No ratings yet
Lab Manual For Python
34 pages
python-2
PDF
No ratings yet
python-2
15 pages
SCIF1131 Week10 Practice
PDF
No ratings yet
SCIF1131 Week10 Practice
9 pages
1write A Python Program To Generate Electricity Bill
PDF
No ratings yet
1write A Python Program To Generate Electricity Bill
12 pages
Chapter 6 Built-In Functions
PDF
No ratings yet
Chapter 6 Built-In Functions
5 pages
AI Python Practical
PDF
No ratings yet
AI Python Practical
12 pages
??? 2024 1068
PDF
No ratings yet
??? 2024 1068
8 pages
Ritik Dabas Program
PDF
No ratings yet
Ritik Dabas Program
20 pages
10303_Exp1
PDF
No ratings yet
10303_Exp1
10 pages
Untitled
PDF
No ratings yet
Untitled
27 pages
Practice Lab 1 - Introduction To Python
PDF
No ratings yet
Practice Lab 1 - Introduction To Python
2 pages
Python Assignment
PDF
No ratings yet
Python Assignment
7 pages
Python Source Code
PDF
No ratings yet
Python Source Code
34 pages
Python Prgs for record class 9th
PDF
No ratings yet
Python Prgs for record class 9th
7 pages
Python Lab Manual 2018 by K.Kesavapandian
PDF
No ratings yet
Python Lab Manual 2018 by K.Kesavapandian
30 pages
Python programmes grade 9
PDF
No ratings yet
Python programmes grade 9
9 pages
CS Project
PDF
No ratings yet
CS Project
20 pages
Aryan Practical CS
PDF
No ratings yet
Aryan Practical CS
28 pages
Nalin FINAL(2) tgjy
PDF
No ratings yet
Nalin FINAL(2) tgjy
52 pages
Python Practical Answers
PDF
No ratings yet
Python Practical Answers
15 pages
Assignment (Jatin)
PDF
No ratings yet
Assignment (Jatin)
61 pages
Aneesh Sridhar Week3 Python
PDF
No ratings yet
Aneesh Sridhar Week3 Python
9 pages
HYPERLINK
PDF
No ratings yet
HYPERLINK
30 pages
Python Practice Programs (Extended Version)
PDF
No ratings yet
Python Practice Programs (Extended Version)
23 pages
Codekata Report 1716960172939
PDF
No ratings yet
Codekata Report 1716960172939
177 pages
Python Basics
PDF
No ratings yet
Python Basics
15 pages
Excercise 1.1
PDF
No ratings yet
Excercise 1.1
5 pages
Python Refresher Course: By:A.Shobharani
PDF
No ratings yet
Python Refresher Course: By:A.Shobharani
43 pages
PROGRAM
PDF
No ratings yet
PROGRAM
7 pages
Sol CH 1
PDF
No ratings yet
Sol CH 1
6 pages
vertopal.com_C_S_practicals (2)
PDF
No ratings yet
vertopal.com_C_S_practicals (2)
18 pages
Python QR
PDF
No ratings yet
Python QR
2 pages
Python 2.7 Quick Reference Sheet: ver 2.01 ʹ 110105 (sjd)
PDF
No ratings yet
Python 2.7 Quick Reference Sheet: ver 2.01 ʹ 110105 (sjd)
2 pages
PYTHON_LAB_ALL
PDF
No ratings yet
PYTHON_LAB_ALL
47 pages
ICS 104 - Introduction To Programming in Python and C: Functions
PDF
No ratings yet
ICS 104 - Introduction To Programming in Python and C: Functions
6 pages
Python Pro 51 To 64 Ashish
PDF
No ratings yet
Python Pro 51 To 64 Ashish
11 pages
Python Pro 51 To 64 Ashish
PDF
No ratings yet
Python Pro 51 To 64 Ashish
11 pages
Pythonprograms Assingment1
PDF
No ratings yet
Pythonprograms Assingment1
16 pages
null
PDF
No ratings yet
null
6 pages
Python 2nd Assignment
PDF
No ratings yet
Python 2nd Assignment
23 pages
Python Lab - Bcomca - Docx - 20240716 - 164225 - 0000
PDF
No ratings yet
Python Lab - Bcomca - Docx - 20240716 - 164225 - 0000
25 pages
PYTHON Lab Manual
PDF
No ratings yet
PYTHON Lab Manual
31 pages
Nalin PRACTICAL PRINT 2025
PDF
No ratings yet
Nalin PRACTICAL PRINT 2025
46 pages