0% found this document useful (0 votes)
30 views

Python Basics Selection and Iteration

The document covers Python basics focusing on selection and iteration through various modules. It includes examples of boolean, integer, string, and float data types, as well as conditional statements and loops. Additionally, it demonstrates the use of the Turtle graphics library and basic arithmetic operations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Python Basics Selection and Iteration

The document covers Python basics focusing on selection and iteration through various modules. It includes examples of boolean, integer, string, and float data types, as well as conditional statements and loops. Additionally, it demonstrates the use of the Turtle graphics library and basic arithmetic operations.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Python Basics: Selection and Iteration

1st Module
a.
my_boolean = True
print(my_boolean)

b.
my_int = 3
print(my_int)

c.
my_string = "This is a string"
print(my_string)

d.
my_float = 3.0
print(my_float)

e.
print("Okay, it is", end=" ")
print("time to learn about operators.")
2nd Module
a.
a = 4 and b = 9

b.
print(not b and not a or not not c)

c.
greeting = "Hello"
place = "world"

print(greeting + " " + place)

d.
result = 7 // 2 # Floor division (//) discards the decimal part
print(result)

e.
a = 3.0
b = int("2")

print(int(a + b))
3rd Module

a.
import sys
x = int(sys.argv[1])
# Check if x is in the specified ranges
if (0 <= x <= 25) or (75 <= x <= 100):
print(str(x) + " is between 0 and 25 or 75 and 100")

b.
import sys
x = int(sys.argv[1])
# Check if x is divisible by 5
if x % 5 == 0:
print(str(x) + " is divisible by 5")
else:
print(str(x) + " is not divisible by 5")

c.
import sys
x = int(sys.argv[1])
# Check if x is divisible by 5 and even
if (x % 5 == 0) and (x % 2 == 0):
print(str(x) + " is divisible by 5 and even")
else:
print(str(x) + " is not divisible by 5 or it is odd")

d.
import sys
x = sys.argv[1]

# Enter your code below


if x == "red":
print(f"{x} is a primary color.")
elif x == "blue":
print(f"{x} is a primary color.")
elif x == "yellow":
print(f"{x} is a primary color.")
else:
print(f"{x} is not a primary color.")
e.
import sys
x = sys.argv[1]

# Enter your code below


if x in "aeiou":
print(f"{x} is a vowel.")
else:
print(f"{x} is not a vowel.")

4th Module

a.

t.forward(100)
t.lt(120)

b.
count = 0
while count < 10:
count = count + 1
c.
sum = 0
i=0

while True:
sum += i
i += 1
if i > 100:
break

print(sum)

d.
for outer_loop in range(4):
for inner_loop in range(4):
t.forward(50)
t.rt(90)
t.forward(100)
for last_loop in range(4):
t.forward(50)
t.rt(90)
e.
for num in range(1,6):
for dots in range(5-num, 0, -1):
print(".", end='')
print(num)

You might also like