0% found this document useful (0 votes)
6 views2 pages

Python Basics: 10 Simple Scripts

The document contains a series of Python scripts demonstrating basic programming concepts. Each script includes user input, processing, and output, covering topics such as printing, arithmetic operations, conditional statements, loops, and mathematical functions. Examples include printing 'Hello, World!', checking for even or odd numbers, calculating factorials, and determining prime numbers.

Uploaded by

renukapriyapydi
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)
6 views2 pages

Python Basics: 10 Simple Scripts

The document contains a series of Python scripts demonstrating basic programming concepts. Each script includes user input, processing, and output, covering topics such as printing, arithmetic operations, conditional statements, loops, and mathematical functions. Examples include printing 'Hello, World!', checking for even or odd numbers, calculating factorials, and determining prime numbers.

Uploaded by

renukapriyapydi
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.

py
print("Hello, World!")
# Output: Hello, World!

2. print_name.py
name = input("Enter your name: ")
print("Your name is", name)
# Input: Alice
# Output: Your name is Alice

3. add_two_numbers.py
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum is", a + b)
# Input: 5, 3
# Output: Sum is 8

4. check_even_odd.py
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
# Input: 4
# Output: Even

5. factorial_loop.py
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial is", fact)
# Input: 5
# Output: Factorial is 120

6. swap_variables.py
a = 5
b = 10
print("Before swap:", a, b)
a, b = b, a
print("After swap:", a, b)
# Output:
# Before swap: 5 10
# After swap: 10 5
7. area_circle.py
import math
r = float(input("Enter radius: "))
area = [Link] * r * r
print("Area of circle:", area)
# Input: 3
# Output: Area of circle: 28.274...

8. leap_year.py
year = int(input("Enter year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap year")
else:
print("Not a leap year")
# Input: 2020
# Output: Leap year

9. reverse_number.py
num = int(input("Enter a number: "))
rev = 0
while num != 0:
rev = rev * 10 + num % 10
num //= 10
print("Reversed number is", rev)
# Input: 123
# Output: Reversed number is 321

10. prime_check.py
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num**0.5)+1):
if num % i == 0:
print("Not Prime")
break
else:
print("Prime")
else:
print("Not Prime")
# Input: 7
# Output: Prime

You might also like