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

Python Code Examples for Basic Calculations

The document contains multiple Python code snippets that perform various tasks, including printing multiplication tables, calculating sums of natural numbers, counting vowels in a string, summing a list, checking for perfect numbers, calculating factorials, generating Fibonacci series, and storing people's names and ages in a dictionary. Each code snippet prompts the user for input and outputs the result accordingly. The document also includes repeated print statements with the text 'vetri' and a unique identifier.

Uploaded by

velselvavetri
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 views11 pages

Python Code Examples for Basic Calculations

The document contains multiple Python code snippets that perform various tasks, including printing multiplication tables, calculating sums of natural numbers, counting vowels in a string, summing a list, checking for perfect numbers, calculating factorials, generating Fibonacci series, and storing people's names and ages in a dictionary. Each code snippet prompts the user for input and outputs the result accordingly. The document also includes repeated print statements with the text 'vetri' and a unique identifier.

Uploaded by

velselvavetri
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

n = int(input("Enter a number to print its multiplication table: "))

i=1

while i <= 10:

print(f"{n} x {i} = {n * i}")


i += 1

print("The total sum is:", n)

print("vetri\n240071601062")
N = int(input("Enter a positive number N: "))

sum = 0

i=1

while i <= N:

sum += i

i += 1

print("The sum of the first", N, "natural numbers is:", sum)

print("vetri\n240071601062")
text = input("Enter a string: ")

vowel_count = 0

vowels = "aeiouAEIOU"

for char in text:


if char in vowels:

vowel_count += 1

print("Number of vowels in the string:", vowel_count)

print("vetri\n240071601062")
def sum_of_list(numbers):

total = 0

for num in numbers:

total += num
return total

my_list = [10, 20, 30, 40, 50]

result = sum_of_list(my_list)

print("The sum of the numbers in the list is:", result)

print("vetri\n240071601062")
N = int(input("Enter a number: "))

if 11 <= N <= 20:

print(f"Multiplication table of {N}:")

for i in range(1, 11):

print(f"{N} x {i} = {N * i}")

else:

print("Number is not between 11 and 20. Please enter a valid number.")

print("vetri\n240071601062")
total = 0

num = int(input("Enter a positive number (0 to stop): "))


while num != 0:

if num > 0 and num % 5 == 0:

total += num

num = int(input("Enter a positive number (0 to stop): "))

print("Sum of positive numbers divisible by 5 is:", total)

print("vetri\n240071601062")
def perfect(num):

divisors_sum = 0

for i in range(1, num):

if num % i == 0:
divisors_sum += i

return divisors_sum == num

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

if perfect(n):

print(n, "is a perfect number.")

else:
print(n, "is not a perfect number:")
print("vetri\n240071601062")
def factorial(n):

result = 1

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

result *= i
return result

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

print(f"The factorial of {num} is {factorial(num)}")

print("vetri\n240071601062")
def fibonacci(n):

if n == 0:

return 0

elif n == 1:
return 1

else:

return fibonacci(n-1) + fibonacci(n-2)

terms = int(input("Enter the number of terms: "))

print("Fibonacci series:")

for i in range(terms):

print(fibonacci(i), end=" ")

print("vetri\n240071601062")
people = {}

n=int(input("enter number of people:"))

for i in range(n):

name = input(f"Enter name of person : ")


age = int(input(f"Enter age : "))

people[name] = age

print("PEOPLE DICTIONARY:",people)

print("vetrivel\n240071601062")
string=input("enter a string:")

freq={}

for ch in string:

freq[ch]= [Link](ch,0)+1
print("characters frequency:",freq)

print("vetri\n240071601062")

You might also like