Edit Template
Edit Template
Edit Template

Python Exercise

Write a Python program to add two numbers provided by the user.
n1 = int(input("Enter 1st number: "))
n2 = int(input("Enter 2nd number: "))
sum = n1 + n2
print("The sum is:", sum)
n = int(input("Enter a number: "))
if n % 2 == 0:
    print("Even")
else:
    print("Odd")
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 is:", a)
elif b > a and b > c:
    print("Largest is:", b)
else:
    print("Largest is:", c)
num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num + 1):
    factorial *= i
print("Factorial of", num, "is", factorial)
string = input("Enter a string: ")
if string == string[::-1]:
    print("It is a palindrome")
else:
    print("It is not a palindrome")
n = int(input("Enter the number of terms: "))
a, b = 0, 1
for _ in range(n):
    print(a, end=" ")
    a, b = b, a + b
num = int(input("Enter a number: "))
is_prime = True
if num > 1:
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            is_prime = False
            break
else:
    is_prime = False
print("Prime" if is_prime else "Not prime")
string = input("Enter a string: ")
reversed_string = string[::-1]
print("Reversed string:", reversed_string)
num = input("Enter a number: ")
sum_of_digits = sum(int(digit) for digit in num)
print("Sum of digits:", sum_of_digits)
numbers = [10, 20, 4, 45, 99]
numbers.sort()
print("Second largest number is:", numbers[-2])
  • All Posts
  • Artificial Intelligence
  • Computer Fundamentals
  • Computer Networks
  • Data Analytics
  • Data Science
  • DBMS
  • Deep Learning
  • Digital Fundamentals
  • DSA with Python
  • Excel
  • Exercise
  • Git & Github
  • Machine Learning
  • Matplotlib
  • Natural Language Processing
  • NumPy
  • Operating System
  • Pandas-s
  • Power BI
  • Python Tutorial
  • Scikit-learn
  • Seaborn
  • SQL & MySQL
Python List

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...

Python String

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...

Python Loops

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...

Conditional Statements

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...

Python Operators

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String...

Python Data Type

Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Hamburger Toggle...

Scikit-learn

Scikit-learn Tutorial Scikit-learn Hamburger Toggle Menu Edit Template Scikit learn in Hindi What is Scikit-learn in Hindi Scikit learn एक...

Pandas

Pandas Tutorial Pandas Hamburger Toggle Menu Edit Template Pandas in Hindi What is Pandas in Hindi pandas  एक python library...

NumPy

NumPy Tutorial NumPy Hamburger Toggle Menu Edit Template NumPy in Hindi What is NumPy in Hindi matplotlib का use हम...

Edit Template
Scroll to Top