0% found this document useful (0 votes)
8 views3 pages

Python Basics: Code Examples and Concepts

The document provides a series of Python programming examples covering basic concepts such as printing output, arithmetic operations, user input, conditional statements, and loops. It includes practical applications like a simple calculator, checking even or odd numbers, finding the largest of three numbers, and creating a multiplication table. Additionally, it demonstrates list usage, a simple chatbot, and defining a basic function.
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)
8 views3 pages

Python Basics: Code Examples and Concepts

The document provides a series of Python programming examples covering basic concepts such as printing output, arithmetic operations, user input, conditional statements, and loops. It includes practical applications like a simple calculator, checking even or odd numbers, finding the largest of three numbers, and creating a multiplication table. Additionally, it demonstrates list usage, a simple chatbot, and defining a basic function.
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

1.

Hello World(Printing output, basic syntax)

print("Hello, World!")

2. Simple Calculator(Arithmetic operators)


a = 10
b = 5
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)

3. Input from User(User input, strings)

name = input("Enter your name: ")


print("Hello,", name)

4. Even or Odd(Conditional statements)

num = int(input("Enter a number: "))


if num % 2 == 0:
print(num, "is even.")
else:
print(num, "is odd.")

5. Find the Largest of Three Numbers(if-elif-else, comparison)

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a >= b and a >= c:


print("Largest:", a)
elif b >= a and b >= c:
print("Largest:", b)
else:
print("Largest:", c)

6. Sum of First N Natural Numbers(Loops, range, variables)

n = int(input("Enter a number: "))


total = 0
for i in range(1, n+1):
total += i
print("Sum is:", total)

7. Multiplication Table(Looping, formatting)

num = int(input("Enter a number: "))


for i in range(1, 11):
print(f"{num} x {i} = {num*i}")

8. List Basics(Lists, loops)

fruits = ["apple", "banana", "cherry"]


for fruit in fruits:
print("I like", fruit)

9. Simple Chatbot (if-else based)

msg = input("You: ")

if "hello" in [Link]():
print("Bot: Hello! How can I help you?")
elif "how are you" in [Link]():
print("Bot: I'm a bot, always good!")
else:
print("Bot: Sorry, I didn’t understand.")
if, in, .lower(), simple logic

10. Basic Function(Functions, parameters)

def greet(name):
print("Hello,", name)

greet("Ananya")

You might also like