FLOAT GET SINGLE CHARACTER
x = float(3) x = "Computer"
print(x) print(x[1])
STRING GET CHARACTER INDEX
a = "Hello" s1="banana"
print(a) print ([Link]("an"))
INPUT GET CHARACTER BY RANGE
print('Enter your name:') x = "Computer"
x = input() print(x[0:4])
print('Hello, ' + x)
REPLACE CHARACTER
NEXT LINE PYTHON
s = 'abc12321cba'
print('YOU \nARE \nGREAT') print([Link]('a', ''))
CONCATENATE ARRAY
a = "Hello" cars = ["Ford", "Volvo", "BMW"]
b = "World"
c = a + " " + b
print(c) WHILE LOOP
# Take user input
number = 2
MULTIPLYING STRING
# Condition of the while loop
x = 'Boom ' while number < 5 :
print(x*3) print("Thank you")
# Increment the value of
OUTPUT: the variable "number by 1"
Boom Boom Boom number = number+1
FOR LOOP NUMBER Generates a random floating-
point number in the interval
for x in range(6): [0,1)
print(x)
uniform(x, y)
It generates a floating-point
value between x and y.
FOR LOOP ARRAY
sample(population, k)
fruits = ["apple", "banana", Selects k unique random
"cherry"] elements from a population
for x in fruits: sequence or set.
print(x)
choice(seq)
STRING UPPER, LOWER, TITLE CASE Chooses a random element from a
non-empty sequence seq.
name='i Love python'
shuffle(x)
#boolean Shuffles list x in place.
print([Link]())
print([Link]()) seed(x)
Generates the same sequence of
#convert random numbers every time you
print([Link]()) call seed(x).
print([Link]())
print([Link]())
ROUND UP OFF DOWN
RANDOMIZER import math
import random The built-in round() function
rounds values up and down.
print([Link](0,9))
The [Link]() function
randint(x, y) rounds down to the next full
Generates a random integer from integer.
x to y, including the x and y.
The [Link]() function rounds
randrange(start, stop, step) up to the next full integer.
Generates a random integer in
the range(start, stop, step)
random()
FORMATTING #get weekday
newval = "{:,.2f}".format(val) bday =
newval ="{:05,.2f}".format(val) [Link](day=25, month
= 10, year =2021)
SORT print([Link]())
cars=[“Ford”,”Volvo”, “BMW”]
[Link]()
[Link](reverse=True) #VALUE
EQUIVALENT----------------
#monday = 0
DATE #tuesday = 1
#wednesday = 2
import datetime #thursday = 3
#friday =4
now = [Link]() #sat = 5
now = [Link]() #sun = 6
bday=[Link](day=1,mo
nth=1,year=2021) [Link]("%d/%m/%Y")
#get details
print([Link]) CONVERTING DATES
print([Link])
print([Link]) from datetime import datetime
print([Link])
print([Link]) date_string = "02/12/2021"
print([Link])
print([Link]) print("date_string =",
date_string)
#min max
[Link] date_object =
[Link] [Link](date_string,
[Link] "%d/%m/%Y")
[Link] #date_object =
[Link](day=int(date_
print([Link]) string[2:4]),
print([Link] month=int(date_string[0:1]),
ion) year=int(date_string[5:9]))
date_object = SAMPLE CODECHUM CODE
date_object.strftime("%B %d ,
%Y") import math
import datetime
#%m = 12 (month)
#%B = 12 to December (month) sched=input('Working Days: ')
#%b = 12 to Dec (month) rate=float(input('Daily Rate:
'))
print("date_object =", bday=input('Birthday: ')
date_object) start=input('Starting Date: ')
end=input('Ending Date: ')
VAT
#deduct days
Vatable Sales = Total Sales/ dayA =
1.12. [Link](day=int(start
VAT = Vatable Sales x 1.12. [3:5]),month=int(start[0:2]),
Total Sales = Vatable Sales + year=int(start[6:10]))
VAT. dayB =
[Link](day=int(end[3
:5]),month=int(end[0:2]),
MONTHS & DAYS year=int(end[6:10]))
1. January – 31 days days = dayB - dayA
days = str(days)
2. February – 28 days in a
common year and 29 days in i=0;
leap years (2024) newday=''
3. March – 31 days
while(days[i]!=' '):
4. April – 30 days newday=newday+str(days[i])
5. May – 31 days i=i+1
6. June – 30 days
7. July – 31 days days = int(newday)
8. August – 31 days
9. September – 30 days #get month
10. October – 31 days x = int(bday[0:2])
y = int(start[0:2])
11. November – 30 days
z = int(end[0:2])
12. December – 31 days
#days divide (1 week equals to
3 days)
dateval = [Link](days / 7)
dateval = dateval * 3
#ifsame month
if(x==y or x==z):
x = int(bday[3:5])
b =
[Link](day=int(bday[
3:5]),month=int(bday[0:2]),
year=int(end[6:10]))
if((b >= dayA) and (b <=
dayB) ):
newrate =
(((rate*2) * dateval) + rate)
else:
b =
[Link](day=int(bday[
3:5]),month=int(bday[0:2]),
year=int(start[6:10]))
if((b >= dayA) and (b
<= dayB) ):
newrate =
(((rate*2) * dateval) + rate)
else:
newrate =
(((rate*2) * dateval))
else:
newrate = (((rate*2) *
dateval))
n = "{:,.2f}".format(newrate)
print('\nGross Pay: '+ str(n))