Programming Fundamentals Lab (Python)
Lab 02 — Comments, Input, Output and Basic Programs
Objective
To familiarize students with comments, input/output statements, escape sequences and basic
Python programs.
Concepts
print() displays output on the screen.
print("Hello Students")
print(10)
print(3.14)
print(10+5)
input() takes value from keyboard.
name = input("Enter your name: ")
print(name)
Type conversion:
age = int(input("Enter age: "))
Comments
Single line comment:
# This is a comment
Multi line comment (docstring):
"""
This is
multi line
comment
"""
Examples
# Basic Program
print("Welcome to Programming Fundamentals Lab")
print("Python is easy to learn")
# Escape Characters
print("Hello\nStudents")
print("Name:\tAli")
# Addition Program
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Sum =", num1 + num2)
Exercises
1) Display your name, ID and course name
2) Print star diagram
Home Work
Take marks of six subjects and display total marks