Getting Started with Python: Data Types, User Input, and Output Formatting

PYTHON

Kishore Babu Valluri

4/23/20253 min read

Python is one of the most beginner-friendly programming languages out there. Whether you're diving into data science, automation, or web development, understanding the basics is your first step. In this post, weโ€™ll cover some core concepts:

  • Python Data Types

  • Taking User Input

  • Output Formatting

๐Ÿ”ข 1. Python Data Types

In Python, every value has a type. Knowing the basic data types helps you store and manipulate different kinds of data effectively.

Example 1: variables

age = 25 # int

height = 5.9 # float

name = "Alice" # str

is_student = True # bool

print(type(age))

print(age)

print(type(height))

print(height)

print(type(name))

print(name)

print(type(is_student))

print(is_student)

Output:

<class 'int'>

25

<class 'float'>

5.9

<class 'str'>

Alice

<class 'bool'>

True

Example 2: Taking user input

Python provides the input() function to accept input from users.

code:

name = input("Enter your name: ")

print("Hello,", name)

#By default, input() returns a string. If you need a number, youโ€™ll need to convert it:

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

print("Next year you will be", age + 1)

Output:
Enter your name: kishore
Hello, kishore
Enter your age: 40
Next year you will be 41

3. Output Formatting

Neat output makes your program user-friendly. Letโ€™s look at different ways to format output in Python.

โœ… 1. Using + to Concatenate

name = "Alice"

print("Hello " + name + "!")

Output:

Hello Alice!

โœ… 2. Using , in print()

age = 25

print("You are", age, "years old.") # Automatically adds space and handles different types

Output:

You are 25 years old.

โœ… 3. Using f-strings (Best Practice)

name = "Alice"

age = 25

print(f"{name} is {age} years old.")

Output:

Alice is 25 years old.

โœ… 4. Formatting Numbers

price = 49.9999

print(f"The price is ${price:.2f}")

Outputs:

The price is $50.00

๐Ÿ’ก f-strings are available in Python 3.6 and above. Theyโ€™re concise and powerful!

๐Ÿ’ฑ Example 1: Currency Conversion

Convert USD to INR (or any currency based on a fixed rate).

# Currency Conversion: USD to INR

usd = float(input("Enter amount in USD: "))

conversion_rate = 83.25 # 1 USD = 83.25 INR (example rate)

inr = usd * conversion_rate

print(f"${usd:.2f} is equivalent to โ‚น{inr:.2f}")

Output:

Enter amount in USD: 3 $3.00 is equivalent to โ‚น249.75

๐Ÿ’ฐ Example 2: Monthly Salary Calculation

Calculate total monthly salary with basic pay, HRA, and allowances.

# Monthly Salary Calculator

basic_pay = float(input("Enter basic pay: "))

hra = float(input("Enter HRA: "))

allowances = float(input("Enter other allowances: "))

total_salary = basic_pay + hra + allowances

print(f"Total Monthly Salary: โ‚น{total_salary:.2f}")

Output:

Enter basic pay: 10000

Enter HRA: 10

Enter other allowances: 2000

Total Monthly Salary: โ‚น12010.00

๐Ÿ›’ Example 3: Simple Bill Calculator

Calculate the total cost of items with quantity and unit price.

# Simple Bill Calculator

item_name = input("Enter item name: ")

price = float(input("Enter price per item: "))

quantity = int(input("Enter quantity: "))

total = price * quantity

print(f"{quantity} x {item_name} @ โ‚น{price:.2f} each = โ‚น{total:.2f}")

Output:

Enter item name: computer

Enter price per item: 70000

Enter quantity: 2

2 x computer @ โ‚น70000.00 each = โ‚น140000.00

๐Ÿงฎ Example 4: Simple Interest Calculator

Calculate interest for a fixed deposit.

# Simple Interest Calculator

principal = float(input("Enter principal amount: "))

rate = float(input("Enter annual interest rate (in %): "))

time = float(input("Enter time in years: "))

simple_interest = (principal * rate * time) / 100

print(f"Simple Interest = โ‚น{simple_interest:.2f}")

Output:

Enter principal amount: 50000

Enter annual interest rate (in %): 10

Enter time in years: 2

Simple Interest = โ‚น10000.00

๐ŸŽ“ Example 5: Student Grade Summary

Accept marks and print average with formatted output.

# Student Grade Summary

name = input("Enter student name: ")

math = float(input("Enter marks in Math: "))

science = float(input("Enter marks in Science: "))

english = float(input("Enter marks in English: "))

average = (math + science + english) / 3

print(f"{name}'s Average Score: {average:.2f}")

Output:

Enter student name: kishore

Enter marks in Math: 90

Enter marks in Science: 95

Enter marks in English: 85

kishore's Average Score: 90.00

๐Ÿš€ Quick Tips Recap:

  • Use float() for decimal inputs.

  • Use int() when you need whole numbers.

  • Format outputs using f-strings: f"{value:.2f}" for 2 decimal places.

  • Build logic step-by-step from user input to output.

Kishore Babu Valluri

Senior Data Scientist | Freelance Consultant | AI/ML & GenAI Expert

With deep expertise in machine learning, artificial intelligence, and Generative AI, I work as a Senior Data Scientist, freelance consultant, and AI agent developer. I help businesses unlock value through intelligent automation, predictive modeling, and cutting-edge AI solutions.