le
vy
Computing Body Hass iolex HSK leop Sbrnotures
while £ For loo p.
We can Cateulate the Body Hass inclex (BHI)
‘Msing beth while £ for loops in py ton,
Using a while loop
| # Prompt the user for weight in Kilograms ana
[height tn mebers,
—wetght = float (input ("Enter your weight tw Kilograns:"))
height = float (input ("6x tor your hetght in meters : "))
H Cateutate BML using avwbele loop
tohele hetght <==0
print (" Hetghb must be greater Ran 0,")
height = Ploat Caputl" Enter your hedght mm meters")
bmi = weight /Chergnt **2)
# Dis play the calculated BMI
print ("Your @Mt is 1" bmi)my a for loop:
#Prompt the user for woeig ht m kilograms andl hety ht :
in meters
weight = float Cinpat (Enter Your weight in Kiley rams s"))
| height a float (input ("Enter Your height in meters) "))
|
# Valtctate hetght ustag a for l
OP
hele hetght <=0:;
Print (8 Hetght must be greater Han 0, wy
| hetght < bloat Comput O"Exter Your hetght in meters :"))
|
# Coloulate But using a dor loop
bmi s wetght (he tght *K 9)
# Display the catoulatedt BMT
| Print C" Your ReL ts! bmi)
| Buteut lasing awhele loop)
|
| Eater your weight tm Kilograns + 70
“i , UTS
Enter your height én meters 3
Your But ts 122.857Tee ee ee @
Butput (using a for boop)
Enter Jour weighb in kilograms: 70
Enter your herghf hk meters » 7S
Your BMt ts) 99. @57
2} Write
clown the Operators in Py Mon Prog ras ming
Py thon
haa two numerte ty pes- Integers
land floating-point numbers - for working with Re
operators temp, Re
| The information stored tn eucoren tes ts
| genoratect referred ts as data. There are twe types
OF mumerie datas integers and real numbers. Integers
| types (iat for short) ore for representing whole numbers,
| Real types for represonthy numbers wik a preotional
part. Snaide Re computer, hese tuo types of dat
jare Stored Arprerentl
, and %,
y Real numbers are represented
| as floating ~point values. A number that has deormal
| point ts afloat even if tts fraction) part es a
| For example Ud tsa Bloat, but Cts an
| inbeger, These two numbers are stored Aipberently
[in he computer.ia Jor numeric date types includan
The opera
Re standard arithmetic operators ae shown below,
Dumerva Operators Example Result
+ | Addition Baal | 85 =
=| Subtraction | 340-01 33.9 |
| te | Maltiplication : an €20 2000 |
| 1 | Float Division V2 | Os a
| | Snteger 4 Diviston| le | oO |
ke Excponenti ration | 4 EK o's 1 20 |
| % 7 Tae mectnal er | 20% 2
| The +,- anol * operators are Strarght
‘forward but note Rat Be a and- operators dan
‘be beth unary anol binary , A unary eperator has
| oh only eno operand + a binary operator has two,
Fer example ,
| The- operator nW-S hs unary eperater
|
ite negate He number 5, whereas the operator
im A-S ds
5 fromh,
oO binary operator for subtracting@_
ts,
3] Prawing Vertors shapes sith Colors and Fon
mere pen control
Set Colora anol Pow:
\Contrett
A turtle ehject contains Ke meMeds for
setting Colours and
2 anak acirele fy ay
fonts. This section introduces
mMeKeds and shows you how te
ts and write tent,
The below table lists Re pen methods for
9 Araoing, color and filling. A ample
Nangle, Spare, & pentagon
ferent colors as Sheusn
lin fegure, The Program alse add text te Ro Areusing,
Turtle Pon Color, Felting anol Drowtng Helos
pr Pell
Method
turtle . celer (o>
| turtle. beyinfill €>
| ahr
turtle. ond fell
|
(ee
| turtle, filleolor (2) :
| FUE Ke shapes
jtartle-fllage> | Returns he pill otakes Gao lf
“turtle. ClearC)
Description _
Sete Ke pen color,
druon before Re |
| last call te begin fill,
Filling , False if not filling,
Clears Re windew, The state acl
ihe position of he turtle not affecfeat. |Fe
| MeMed
turtle. reset 0)
' Desertption
clears Re yoindous and reset Re
State and the position to the ovighel
defautt value. |
————}
———————— 4 |
forte. Soreensize(y, i) Sete fe widlththeight of Bocere
eer es ere ce |
turtle. hide turtle 0) Makes Ke turtle invisible, |
tC. - |
turtle. shaw turtlel) Makes fhe turtle visrble, |
turtle. tsvisible 0): |
ae aE! —
Returns Tree (2 the turtle is visible,
— |
turtle, write (s, | Nrttes the String 3 on He turtle |
fonts (Areal, g |
| oo Position, Fort & a triple Consisting |
uw ue i
| normal") | Ob fontname, fontsize and |
| | : font ty pe,
Color shapes. py
Import turtle 2
pen Hhickness tp 3 pixele
& turtle. penup C) # Putt fhe pen ap
|S turtle. gote (-206, 50)
© turkle. pendown 0) # Patt He pen dousn
7 turtlee begin fill CD # Beg'n to fill color ea shape
| & tetle.color (red)
14 turtle. eirete (40, step==3) # Draw a treanale22
22
24
25
26
27,
22
30
3t
32
turtle ,
tertles end _Ptted # Et He shape
Penup 0)
turtle -Joto C-to0, -50)
turkle . Perolousy 0)
turtle. begmprttcy y Begin to fill colour in sho pe
turtle. Coto, blue")
turtle. Cercle Cho, Steps = A) 4 Draw a Sqore
turtle. end pricy HEC Re shape
turtle, Penup 0
turtle | gots (6, -So)
turtle. Perdown (9
turtle , begin patt OD # Begin te fill color in Shape
turtle. color C'green”
turtle. circle (Ae, steps=5) y Drow a pentagon
turtle. end #0) # Fol tke shape
turtle. Pennp C)
turtle, goto (too, -50)
turtle, pendown 0)
turtle. begin _ felled
turtle,
Color C* yellow ")turtle. trcle (40, step #6) Y Drow o hexagon .
33
3k
35
3b
37
32
34
Ao
At
Ay
AZ
Ak
AS
Ab
47
Ag
AA
59
Sl
turtle end fill Cd # Ell the shape
turtle « penup C)
turtle. gots (200, -50)
turtle. pendown C)
turtle. begin fel ¢) # Begin te fall color dn shape
turtle. aplor C* purple")
turtles cercle CAO) # Draw eelrcle
turtle, en fill 0) # FUL the chape
turtle. color C’green")
turtle. penap CD
turtle. gete (-100, So)
turtle. pondown 0)
turtle write ("Cool Colourful Shapes”
font = (’Times”, 18, beta")
turtle. hicle turtle)
turtle. dene C)\ ae
/ hopes? PY
amples P
ol