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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 51 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 45 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 23 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 83 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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__)

0 commit comments

Comments
 (0)