0% found this document useful (0 votes)
20 views3 pages

Python Programming Basics Guide

The document contains Python programming exercises covering various topics such as using operators, user input functions, conditional statements, and type conversion. Each section includes example code demonstrating the concepts, such as calculating area, checking user eligibility to vote, and manipulating strings. Overall, it serves as a practical guide for learning intermediate Python programming.

Uploaded by

Jannah Santos
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Python Programming Basics Guide

The document contains Python programming exercises covering various topics such as using operators, user input functions, conditional statements, and type conversion. Each section includes example code demonstrating the concepts, such as calculating area, checking user eligibility to vote, and manipulating strings. Overall, it serves as a practical guide for learning intermediate Python programming.

Uploaded by

Jannah Santos
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NAME: JANNAH T.

SANTOS

INTERMEDIATE PROGRAMMING – PYTHON

1CSA

write a program for each topic

Python Basics-Using Operators


Code:
w = float(input("Enter width: "))
h = float(input("Enter height: "))
print("Area:", w * h)

User Input function in Python


Topics:
 user input function
 upper()
 lower()
 capitalize()
Code:
name = input("Enter your full name: ")
print("UPPERCASE:", [Link]())
print("lowercase:", [Link]())
print("Capitalized:", [Link]())

Conditional statement in Python using if-else


Code:
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are NOT eligible to vote.")

Conditional statement in Pythonb using while and if


Code:
secret_number = 7
while True:
guess = int(input("Guess the number (1-10): "))

if guess == secret_number:
print("🎉 Correct! You guessed the number.")
break
elif guess > secret_number:
print("Too high! Try again.")
else:
print("Too low! Try again.")

Using "in" and "not" functions in Python


Code:
shopping_list = ["milk", "bread", "eggs", "butter", "sugar"]

item = input("Enter an item to check: ").lower()

if item in shopping_list:
print(f"{[Link]()} is in the shopping list. ✅")
else:
print(f"{[Link]()} is NOT in the shopping list. ❌")

Using "range" in Python (PART 1 & 2)


Code:
n = int(input("Enter a number: "))

print("First", n, "even numbers:")


for i in range(2, n * 2 + 1, 2):
print(i, end=" ")

Type Conversion in Python


Code:
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
int_sum = int(num1) + int(num2)
float_product = float(num1) * float(num2)

print("Sum (as integers):", int_sum)


print("Product (as floats):", float_product)

Python Basics (Built-in Methods) - Part 1 & 2


Code:
sentence = input("Enter a sentence: ")

word_count = len([Link]())
uppercase_sentence = [Link]()
hyphen_sentence = [Link](" ", "-")
reversed_sentence = sentence[::-1]

print("\nSentence Analysis:")
print("Word count:", word_count)
print("Uppercase:", uppercase_sentence)
print("With hyphens:", hyphen_sentence)
print("Reversed:", reversed_sentence)

You might also like