Curriculum
Course: Python-100-Programmes
Login
Text lesson

A-Basic-Input/Output-(1 to 9)

A-Basic Input/Output: (1 to 9)

  1. Write a program to input your name and print it.

Here is a simple beginner Python program:

name = input(“Enter your name: “)

print(name)

 

Output example:

Enter your name: Abhijit

Abhijit

 

  1. Input your age and print “You are X years old”.

 

Here is a simple Python program:

age = input(“Enter your age: “)

print(“You are”, age, “years old”)

 

Example Output:

Enter your age: 15

You are 15 years old

 

  1. Input “ Welcome to Python Programming” message and display it.

 

Here is a simple Python program to input a message and display it exactly as you asked:

Python Program : 

 

Here is a simple Python program:

message = input(“Enter a message: “)

print(message)

 

Output:

Enter a message: Welcome to Python Programming

Welcome to Python Programming

 

If you want it without user input (just display the message directly), use:

print(“Welcome to Python Programming”)

  1. Input two numbers and display their Sum, Difference, Multiplication, Division, Square, and Cube.

 

Here is a simple beginner Python program:

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

b = int(input(“Enter second number: “))

 

print(“Sum =”, a + b)

print(“Difference =”, a – b)

print(“Multiplication =”, a * b)

print(“Division =”, a / b)

 

print(“Square of first number =”, a * a)

print(“Cube of first number =”, a * a * a)

 

print(“Square of second number =”, b * b)

print(“Cube of second number =”, b * b * b)

 

Example Output:

Enter first number: 6

Enter second number: 3

Sum = 9

Difference = 3

Multiplication = 18

Division = 2.0

Square of first number = 36

Cube of first number = 216

Square of second number = 9

Cube of second number = 27

  1. Enter a number and print the next and previous numbers.

Here is a simple Python program:

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

 

print(“Previous number:”, num – 1)

print(“Next number:”, num + 1)

 

Example Output:

Enter a number: 10

Previous number: 9

Next number: 11

  1. Input two numbers and swap them.

 

Here is a simple Python program to swap two numbers:

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

b = int(input(“Enter second number: “))

 

a, b = b, a

 

print(“After swapping:”)

print(“First number =”, a)

print(“Second number =”, b)

 

Example Output:

Enter first number: 5

Enter second number: 10

After swapping:

First number = 10

Second number = 5

 

  1. Convert kilometres to meters.

Here is a simple Python program to convert kilometres to meters:

km = float(input(“Enter distance in kilometers: “))

meters = km * 1000

print(“Distance in meters:”, meters)

 

Example Output:

Enter distance in kilometers: 2.5

Distance in meters: 2500.0

 

  1. Convert Celsius temperature to Fahrenheit.

 

Here is a simple Python program to convert Celsius to Fahrenheit:

celsius = float(input(“Enter temperature in Celsius: “))

fahrenheit = (celsius * 9 / 5) + 32

print(“Temperature in Fahrenheit:”, fahrenheit)

 

Example Output:

Enter temperature in Celsius: 25

Temperature in Fahrenheit: 77.0

  1. Convert Fahrenheit temperature to Celsius.

Here is a simple Python program to convert Fahrenheit to Celsius:

fahrenheit = float(input(“Enter temperature in Fahrenheit: “))

celsius = (fahrenheit – 32) * 5 / 9

print(“Temperature in Celsius:”, celsius)

 

Example Output:

Enter temperature in Fahrenheit: 77

Temperature in Celsius: 25.0

Scroll to Top