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

Python Code Examples for Beginners

The document contains a series of Python code snippets demonstrating various programming tasks, including ATM withdrawal simulations, calculating the average of numbers, checking for Armstrong numbers, determining leap years, calculating employee salaries, computing factorials, generating Fibonacci series, finding squares of numbers, reversing strings, and summing numbers. Each snippet includes user input and basic control structures. The examples illustrate fundamental programming concepts and operations.

Uploaded by

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

Python Code Examples for Beginners

The document contains a series of Python code snippets demonstrating various programming tasks, including ATM withdrawal simulations, calculating the average of numbers, checking for Armstrong numbers, determining leap years, calculating employee salaries, computing factorials, generating Fibonacci series, finding squares of numbers, reversing strings, and summing numbers. Each snippet includes user input and basic control structures. The examples illustrate fundamental programming concepts and operations.

Uploaded by

shaji chellayyan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

ATM withdrawal simulations

balance = 5000

withdraw = int(input("Enter amount: "))

if withdraw > balance:

print("Insufficient Balance")

elif withdraw % 100 != 0:

print("Enter amount in multiples of 100")

else:

balance -= withdraw

print("Balance:", balance)

2. average of N numbers

n = int(input("How many numbers? "))

total = 0

for i in range(n):

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

total += num

avg = total / n

print("Average is", avg)

3. Check armstrong number


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

temp = num

sum = 0

while temp > 0:

digit = temp % 10

sum += digit ** 3

temp //= 10

if sum == num:

print("Armstrong")

else:

print("Not Armstrong")
4. Check leap year
year = int(input("Enter year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):

print("Leap year")

else:

print("Not leap year")

5. Employee salary calculation


employees = [

{"name": "John", "basic": 5000},

{"name": "Alice", "basic": 7000},

{"name": "Bob", "basic": 6500}

for emp in employees:

hra = emp["basic"] * 0.1

da = emp["basic"] * 0.05

gross = emp["basic"] + hra + da

print(emp["name"], "Gross Salary:", gross)

6. Factorial of a number
num = int(input("Enter number: "))

fact = 1

for i in range(1, num + 1):

fact = fact * i

print("Factorial:", fact)
7. fibonacci series
n = 10

a, b = 0, 1

print(a, b)

for i in range(2, n):

c=a+b

print(c)

a=b

b=c

8. Find square of each number


nums = [1, 2, 3, 4]

squares = []

for i in nums:

[Link](i*i)

print("Squares:", squares)

9. Reverse a string
balance = 5000

withdraw = int(input("Enter amount: "))

if withdraw > balance:

print("Insufficient Balance")

elif withdraw % 100 != 0:

print("Enter amount in multiples of 100")

else:

balance -= withdraw

print("Balance:", balance)
10. Sum of n numbers
n = int(input("Enter a number: "))

sum = 0

for i in range(1, n + 1):

sum += i

print("Sum is:", sum)

You might also like