Skip to content

FrdAzdn/Python-Topic-1-2-3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

TOPIC 1 (VARIABLES)

Variables = A container for a value (string, integer, float, boolean)

A variable behaves as if it was the value it contains.

first_name = "Zephyr" print(f"Hello {first_name}.") food = "Shawarma" print(f"I like {food}.") email = "classified" print(f"My email is {email}.\n")

Above are all STRINGS. (Must put PARENTHESES "" /'')

age = 27 items = 15 num_of_people = 200

print(f"I am {age} years old.") print(f"I need to bring {items} items tomorrow.") print(f"There's around {num_of_people} here.\n")

Above are all INTEGERS. (No PARENTHESES)

CGPA = 3.33 price = 12.90 weight = 64.1

print(f"My diploma CGPA is {CGPA}.") print(f"Eggs price nowadays are {price}.") print(f"My weight is {weight}.\n")

Above are all FLOATS, (No PARENTHESES), (DECIMAL NUMBERS)

cybersec_exp = True

if cybersec_exp: print("You are a legendary hacker.") else: print("Go harder!!!.")

bec_rich = False

if bec_rich: print("I am getting there.") else: print("Keep going!!!.")

I_L_whatido = False

if I_L_whatido: print("I will make it.\n") else: print("I will still make it!!!.\n")

Above are all BOOLEANS,(TRUE OR FALSE ONLY) (IF & ELSE ONLY)

Do not forget UNDERSCORE "_" character!!!

################################################################################### ################################################################################### ###################################################################################

TOPIC 2 (TYPECASTING)

Typecasting = The process of converting a variable from one data type to another

str(), int(), float(), bool().

name = "Zephyr" age = 27 CGPA = 3.33 a_hacker = True

print(type(name)) print(type(age)) print(type(CGPA)) print(type(a_hacker))

Above are to reveal VARIABLE data types

"print(type(variable))"

age = str(age) print(age) print(type(age))

age = float(age) print(age) print(type(age))

CGPA = int(CGPA) print(CGPA) print(type(CGPA))

a_hacker = str(a_hacker) print(a_hacker) print(type(a_hacker))

name = bool(name) print(name) print(type(name))

Above are to convert a variable from one data type to another

str(), int(), float(), bool().

Don't forget to print!!!

################################################################################### ################################################################################### ###################################################################################

TOPIC 3 (USER INPUT)

input() = A function that prompts the user data to enter data

Returns the entered data as a string

name = input("What is your name?: ") age = int(input("How old are you?: "))

age += 1

print(f"Hola {name}!") print ("SANNAH HELWAH!!!") print(f"You are {age} years old.")

Above are Exercise User Input

length = float(input ("Enter the length: ")) width = float(input ("Enter the width: ")) area = length * width

print(f"The area is: {round(area, 2)}cm.")

Above are Exercise 1 Rectangle Area Calc

item = input("What is your item?: ") price = float(input("Enter the price: ")) quantity = int(input("Enter the quantity: ")) total = price * quantity

print(f"You have bought {quantity} x {item}") print(f"The total is: RM{round(total, 2)}")

Above are Exercise 2 Shopping Cart Program

About

TOPIC 1 (VARIABLES)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published