System Scripting Lab 06

Python Basics

Setup

mkdir lab06
cd lab06
idle3

Python Interactive Examples:

5 + 6     # 11
4 * 2     # 8
6 / 4     # 1.5

Variables

x = 10
print(x)

# Print with text
print("Value of x is:", x)

Exercise 1: Variables

1. Valid Variable Names

2. Data Types

Exercise 2: Boolean Operators

Given:

a = False
b = True
c = False

Results:

Comparisons (x = 3)

Exercise 3: User Input Script

# Request user name
name = input("Enter your name: ")

# Request year of birth
year = int(input("Enter your year of birth: "))

# Calculate age (assuming current year = 2026)
age = 2026 - year

# Output message
print("Welcome", name)
print("You are", age, "years old")

Exercise 4: Formatted Output

print("Twinkle, twinkle, little star,")
print("How I wonder what you are!")
print("Up above the world so high,")
print("Like a diamond in the sky.")
print("Twinkle, twinkle, little star,")
print("How I wonder what you are")

Note: Repeat the block again to match required output.

Exercise 5: Single Print Multi-line Output

# Get user input
name = input("Enter your name: ")
age = input("Enter your age: ")
address = input("Enter your address: ")

# Print in one statement
print("Name:", name, "\nAge:", age, "\nAddress:", address)

Explanation:

Key Exam Tips