Aug 3, 2024
a = 10
b = 20
x % y
returns remainder of x
divided by y
.input()
function to receive user input and assign to variables:
name = input("Enter your name:")
age = int(input("Enter your age:"))
print()
function to display output:
print(f"My name is {name}, my age is {age}.")
if age > 18:
print("Eligible to vote")
else:
print("Not eligible to vote")
for i in range(1, 11):
print(i)
while count < 5:
count += 1
def
keyword:
def add(a, b):
return a + b
result = add(3, 5)
class Dog:
def bark(self):
print("Woof!")
my_dog = Dog()
my_dog.bark()
try:
# Code that may cause an exception
except ValueError:
print("Invalid input")
with open('file.txt', 'r') as file:
content = file.read()
with open('output.txt', 'w') as file:
file.write("Hello, World!")