Skip to content

Commit ec41b2b

Browse files
Add files via upload
1 parent b21b6a0 commit ec41b2b

21 files changed

+708
-0
lines changed

Date_module.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Python Dates
2+
#A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects.
3+
4+
#Example
5+
#Import the datetime module and display the current date:
6+
7+
import datetime
8+
9+
x = datetime.datetime.now()
10+
print(x.year)
11+
print(x.strftime("%A"))
12+
print(x)
13+
x = datetime.datetime(2020, 5, 17)
14+
#The datetime() class also takes parameters for time and timezone (hour, minute, second, microsecond, tzone)
15+
#but they are optional, and has a default value of 0, (None for timezone).
16+
print(x)

Finaltest.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
def adding_report(type="T"):
2+
value=""
3+
total=0
4+
count=0
5+
j=0
6+
items=""
7+
if(type=='T'):
8+
print("Input an integer to add to the total or 'Q' to quit:")
9+
while True:
10+
value=input("Enter an integer or 'Q':")
11+
if(value=='Q'):
12+
break
13+
elif(value=='q'):
14+
break
15+
elif(value=='Quit'):
16+
break
17+
if(value.isdigit()):
18+
total=total+int(value)
19+
elif(value.isalpha()):
20+
print(value," is inavlid input")
21+
print("Total")
22+
print(total)
23+
24+
elif(type=='A'):
25+
print("Input an integer to add to the total or 'Q' to quit:")
26+
while True:
27+
value=input("Enter an integer or 'Q':")
28+
if(value=='Q'):
29+
break
30+
elif(value=='q'):
31+
break
32+
elif(value=='Quit'):
33+
break
34+
if(value.isdigit()):
35+
count=count+1
36+
items=items+value+"\n"
37+
total=total+int(value)
38+
elif(value.isalpha):
39+
print(value," is inavlid input")
40+
print("items:")
41+
print("\n",items)
42+
print("Total:")
43+
print(total)
44+
45+
46+
while True:
47+
print("Report type includes All items report (A) or Total sum (T):")
48+
type=input("Choose report type 'A' or 'T':")
49+
adding_report(type)
50+
break
51+

Json.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#python has a built in module for json
2+
#converting from json to python
3+
import json
4+
# some JSON:
5+
x = '{ "name":"John", "age":30, "city":"New York"}'
6+
y=json.loads(x)
7+
#python word
8+
print(y["age"])
9+
#converting from python to json
10+
x={"name":"John", "age":30, "city":"New York"}
11+
y=json.dumps(x)
12+
#json string
13+
print(y)

LISTwork.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
letters=['A','B','C','D']
2+
print(letters,type(letters))
3+
4+
numbers=[1,2,3,4,5,6]
5+
print(numbers,type(numbers))
6+
7+
8+
Mixedlist=["Sheeza","Kinza",12345,numbers,letters]
9+
print(Mixedlist,type(Mixedlist))
10+
11+
12+
print(numbers[0]+numbers[1]+numbers[2])
13+
print(numbers[-3]+numbers[-1]+numbers[-2])
14+
Mixedlist.append("Tayyab")
15+
print(Mixedlist)
16+
#using indexing you can replace items in alist but can not add a value at a new index.
17+
# for the purpose of new index one can use insert method in list
18+
numbers.insert(6,7)
19+
print(numbers)
20+
numbers.insert(7,"Sheeza")
21+
print(numbers)
22+
numbers.insert(2,"Aliza")
23+
print(numbers)
24+
del numbers[2]
25+
print(numbers)
26+
del numbers[-1]
27+
print(numbers)
28+
# poping items from the list without argument pop() method,,,It pop from right to left
29+
print(letters)
30+
print(letters.pop())
31+
print(letters)
32+
#can also pop specific item using pop(index)
33+
34+
print(letters)
35+
print(letters.pop(1))
36+
print(letters)
37+
while Mixedlist:
38+
print(Mixedlist.pop(),"Just check list",Mixedlist)
39+
# nOw the remove method where we give item as a parameter to remove but in previous work we were giving index:
40+
words=["ok","hell","dream","wow"]
41+
while "hell" in words:
42+
words.remove("hell")
43+
print(words)
44+
45+

Teststrings.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
quote=input("enter a 1 sentence quote, non-alpha separate words:").lower()
2+
word=""
3+
for check in quote:
4+
if(check.isalpha()):
5+
word+=check
6+
else:
7+
if(word and word[0]
8+
> "g" ):
9+
print(word.upper())
10+
word = ""
11+
else:
12+
word = ""
13+
print(word.upper())

check.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def adding_report(report="T"):
2+
total = 0
3+
items = ""
4+
while True:
5+
int_input = input("Input an integer to add to the total or Q to quit: ")
6+
if int_input.isdigit() == True:
7+
total = int(total) + int(int_input)
8+
if report.upper() == "A":
9+
items = items + int_input + "\n"
10+
elif int_input.upper().startswith("Q") == True:
11+
if report.upper() == "A":
12+
print("\n" + "Items: " + "\n" + str(items))
13+
print("Total: " + str(total))
14+
break
15+
elif report.upper() == "T":
16+
print("\n" + "Total: " + str(total))
17+
break
18+
else:
19+
print("Invalid input.")
20+
21+
adding_report()
22+
x = ["this", "is", "a" True "list"]
23+
print(x)

checking.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def self():
2+
"""Function for self introduction."""
3+
print("My name is Sheeza.")
4+
print(self.__doc__)

class.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Person:
2+
def __init__(self, name, age):
3+
self.name = name
4+
self.age = age
5+
6+
p1 = Person("John", 36)
7+
8+
print(p1.name)
9+
print(p1.age)

conditions.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
def test():
2+
x=9+4
3+
print("if answer is true it is ",x==13)
4+
print("check whether it is true : its",3+3<2+4)
5+
test()
6+
7+
def test2(x,y):
8+
if(y>=x+x):
9+
print(y, "greater than or equal", x + x ,"is true.")
10+
else:
11+
x = 3
12+
y = x + 8
13+
14+
x=input("Enter x:")
15+
y=input("Enter y:")
16+
test2(x,y)
17+
if("Hello">"hello"):
18+
print("True")
19+
else:
20+
print("False")
21+
name = "Tobias"
22+
23+
print(name == "Alton")
24+
#check casting
25+
str_integer='700'
26+
int_number=200
27+
number_total=int_number+int(str_integer)
28+
print(number_total)
29+
a=int(input("enter digits:"))
30+
b=int(input("enter digits:"))
31+
output=a+b
32+
print(a,"+",b,"=",output)
33+
34+
size_num = "8 9 10"
35+
36+
size = "8" # user input
37+
38+
if size.isdigit() == False:
39+
print("Invalid: size should only use digits")
40+
elif int(size) < 8:
41+
print("size is too low")
42+
elif size in size_num:
43+
print("size is recorded")
44+
else:
45+
print("size is too high")
46+
47+
48+
num="20"
49+
if(num.isdigit()):
50+
print("ok",num.isdigit())
51+
else:
52+
print("NO",num.isdigit())
53+
operator=input("Select operator(*,/):")
54+
a=int(input("enter digits:"))
55+
b=int(input("enter digits:"))
56+
def multiply(a,b,ope):
57+
if(ope=="/"):
58+
c=a/b
59+
equa=str(a)+"/"+str(b)+"="+str(c)
60+
return equa
61+
elif(ope=="*"):
62+
c=a*b
63+
equa=str(a)+"*"+str(b)+"="+str(c)
64+
return equa
65+
else:
66+
print("Invalid operator")
67+
print(multiply(a,b,operator))
68+
calculation = 5 + 3 + 3 * 2 - 1
69+
print(calculation)
70+
71+
maximum=100
72+
minimum=50
73+
price=144
74+
value=float(input("Enter cheese order weight (numeric value):"))
75+
def cheese_order(val,max,min,p):
76+
if val>max:
77+
print(val,"is more than currently available stock.")
78+
elif val<min:
79+
print(val,"is below minimum order amount.")
80+
else:
81+
print(val,"costs","$"+str(p),".")
82+
cheese_order(value,maximum,minimum,price)
83+

docstring.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def self():
2+
"""Function for self introduction."""
3+
print("My name is Sheeza.")
4+
print(self.__doc__)

finaltestithink.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def str_analysis(pass_argument):
2+
if(pass_argument.isdigit()):
3+
int_conversion=int(pass_argument)
4+
if(int_conversion>90):
5+
printvalue=str(int_conversion)+" "+"is pretty big number."
6+
return printvalue
7+
elif(int_conversion<90):
8+
printvalue=str(int_conversion)+" "+"is pretty small number than expected."
9+
return printvalue
10+
else:
11+
printvalue=str(int_conversion)+" "+"is number between expected."
12+
return printvalue
13+
elif(pass_argument.isalpha()):
14+
printvalue=pass_argument+" "+"is all alphabetical characters!"
15+
return printvalue
16+
else:
17+
printvalue=pass_argument+" "+"neither all alpha nor all digit."
18+
return printvalue
19+
20+
21+
while True:
22+
stro=input("enter a word or a digit:")
23+
if(stro!=""):
24+
print(str_analysis(stro))
25+
break
26+
27+

function.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
def first_code():
2+
print("My name is Sheeza.")
3+
print("This is my first function.")
4+
first_code()
5+
def yel_it(phrase):
6+
print(phrase.upper()+"!")
7+
yel_it("This is all jokes.")
8+
9+
#for default values:
10+
def yel_it(phrase="This is me."):
11+
print(phrase.upper()+"!")
12+
#Passing value
13+
yel_it("This is all jokes.")
14+
#for default value
15+
yel_it()
16+
#Another task
17+
phrase=input()
18+
yel_it(phrase)
19+
def add_num(num_1 = 10):
20+
print(num_1 + num_1)
21+
add_num()
22+
#Another task with return
23+
def make_doctor(name):
24+
return name
25+
full_name=input()
26+
print(make_doctor(full_name))
27+
#Another task
28+
def make_schedule(period1, period2 ,peroid3):
29+
schedule = ("\n[1st] " + period1.title() + "\n[2nd] " + period2.title()+"\n[3nd] " + peroid3.title())
30+
return schedule
31+
32+
student_schedule = make_schedule("mathematics", "history","Science")
33+
print("SCHEDULE:", student_schedule)
34+
35+
def add_numbers(num_1, num_2 = 10):
36+
return num_1 + num_2
37+
print(add_num(100))
38+
def bird_available(bird):
39+
bird_types = 'crow robin parrot eagle sandpiper hawk pigeon'
40+
if(bird in bird_types):
41+
return True
42+
else:
43+
return False
44+
bird=input()
45+
value=bird_available(bird)
46+
if(value==True):
47+
print("The",bird,"available is true.")
48+
else:
49+
print("The",bird,"available is false.")
50+
#task
51+
def how_many():
52+
requested = input("enter how many you want: ")
53+
return requested
54+
55+
# get the number_needed
56+
number_needed = how_many()
57+
print(number_needed, "will be ordered")
58+
59+
def fishstore(fish,price):
60+
sentence="Fishtype:"+" "+fish+" "+"costs"+" "+"$"+price
61+
return sentence
62+
fish=input("enter the fish name:")
63+
price=input("enter the fish price(no symbols):")
64+
print(fishstore(fish,price))
65+
year = "2001"
66+
67+
if year.isdigit():
68+
print(year, "is all digits")
69+
else:
70+
pass
71+
72+
73+

0 commit comments

Comments
 (0)