[go: up one dir, main page]

0% found this document useful (0 votes)
10 views17 pages

Session 3

Uploaded by

hemesh7204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views17 pages

Session 3

Uploaded by

hemesh7204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Move The Turtle

CrEAST

Under CrEAST 2024-25


CrEAST
Exam Time

Baseline Test
on Quizizz
Do you know ?
How to calculate area of Rectangle ?? length = float(input("Enter length: "))

Area of a rectangle = length × width . width = float(input("Enter width: "))

Can you write a program to calculate area of area = length * width


rectangle??
print 'Area =', area
Input from user: length and width.

Output : calculated area of rectangle.


Data Type
Integers - Whole numbers without decimal points

Floating point numbers - Numbers with a decimal point

Strings = a string is a sequence of characters, typically enclosed within single


quotes (’...’) or double quotes (”...”).
What will be o/p ?
x=5
o/p will be 5 or True
y = 10

result = x<y Ans wer => True


print result

Boolean type - True / False


Boolean values- Represents logical
values: True or False
Open turtle mode
import turtle
t = turtle.Turtle()
t.shape('turtle')
t.color('red')
for x in range(13):
t.forward(200) What happens if we try
t.left(150) changing the range and
the left angle?
Check interesting output
import turtle
t = turtle.Turtle()
t.shape('turtle')
Speed
t.color('red') 1:slowest, 3:slow, 5:normal, 10:fast, 0:fastest
t.speed(10)
for x in range(100):
t.forward(200)
t.left(175)
Lets study
Arithmetic Operators

Operator Description Example

+ Addition 5+3=8

- Subtraction 10 - 4 = 6

* Multiplication 2 * 7 = 14

/ Division (returns a float) 12 / 5 = 2.4

** Exponentiation (raises a number to a power) 2 ** 3 = 8

% Modulo (returns the remainder of division) 9%4=1


Lets understand
Comparison Operators: Compare values and return boolean results (True or False):

Operator Description Example


== Equal to x == y
!= Not equal to x != y
< Less than x<y
> Greater than x>y
<= Less than or equal to x <= y
>= Greater than or equal to x >= y
Assignment operator
Assign values to variables

Operator Description Example

= Assigns a value to variable x = 5


Understand if statement and indentation
a = 33

b = 200

if b > a:

print("b is greater than a")


If you want to test 2 conditions
The elif keyword is Python's way of saying "if the previous conditions were not true,
then try this condition".

a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
Assignment - traffic light ( use of if else )
import turtle
t = turtle.Turtle()
t.speed(5)
color = "red"
t.penup()
if color == "red":
t.color("red")
elif color == "yellow":
t.color("yellow")
elif color == "green":
t.color("green")
t.pendown()
t.begin_fill()
t.circle(20)
t.end_fill()
Assignment part 2 - draw green circle if even and blue if odd
import turtle
t = turtle.Turtle()
t.speed(2)
for i in range(6):
if i % 2 == 0:
t.color("blue")
else:
t.color("green")

t.begin_fill()
t.circle(10) # Draw a circle with a radius of 30
t.end_fill()

t.penup()
t.forward(30)
t.pendown()
LETS try # Spinning effect
import turtle
screen = turtle.Screen() # Creating a turtle screen
screen.bgcolor("PINK")
pen = turtle.Turtle() # Creating a turtle
pen.shape("turtle")
pen.color("blue")
for i in range(36):
pen.right(10) # Rotates the turtle by 10 degrees gives # Spinning effect
turtle.done()
Thank you !!
That's it for session 3…
https://forms.gle/B9frfFTJZj3ajs639

You might also like