first upload
This commit is contained in:
parent
f4265a2372
commit
4e24c374be
|
@ -0,0 +1,9 @@
|
|||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = 0
|
||||
|
||||
for arg in sys.argv:
|
||||
if(arg.isdecimal()):
|
||||
result += int(arg)
|
||||
print(result)
|
|
@ -0,0 +1,6 @@
|
|||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Arguments count: {len(sys.argv)}")
|
||||
for i, arg in enumerate(sys.argv):
|
||||
print(f"Argument {i:>6}: {arg}")
|
|
@ -0,0 +1,35 @@
|
|||
class Root():
|
||||
a = "Root"
|
||||
def f(self):
|
||||
print(self.a)
|
||||
pass
|
||||
|
||||
class A(Root):
|
||||
a = "A"
|
||||
def f(self):
|
||||
print(self.a)
|
||||
super().f()
|
||||
pass
|
||||
|
||||
class B(Root):
|
||||
a = "B"
|
||||
def f(self):
|
||||
print(self.a)
|
||||
super().f()
|
||||
pass
|
||||
|
||||
class C(A, B):
|
||||
# C is a child of A and B, which are siblings. Therefore incest.
|
||||
# You may laugh now.
|
||||
def f(self):
|
||||
print("C")
|
||||
super().f()
|
||||
print(C.__mro__) # Method Resolution Order(MRO)
|
||||
pass
|
||||
|
||||
def main():
|
||||
o = C()
|
||||
o.f()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1,6 @@
|
|||
print("hello world!\n")
|
||||
for i in range(10):
|
||||
if(i<9):
|
||||
print((i)*"hello-"+"hello")
|
||||
elif(i==0):
|
||||
print("hello")
|
|
@ -0,0 +1,11 @@
|
|||
import random
|
||||
import string
|
||||
|
||||
|
||||
def get_random_string(length):
|
||||
# choose from all lowercase letter
|
||||
letters = string.ascii_lowercase
|
||||
result_str = ''.join(random.choice(letters) for i in range(length))
|
||||
return result_str
|
||||
|
||||
print(get_random_string(20))
|
|
@ -0,0 +1,65 @@
|
|||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = 0
|
||||
|
||||
def help(): {
|
||||
print("input: [value] [operation] [value]\noperations: [ + - . / ]\n")
|
||||
}
|
||||
|
||||
if(len(sys.argv) > 1):
|
||||
if(sys.argv[1] == "-h" or sys.argv[1] == "--help"):
|
||||
help()
|
||||
sys.exit()
|
||||
if(len(sys.argv) == 0):
|
||||
help()
|
||||
sys.exit()
|
||||
|
||||
if(len(sys.argv) < 4):
|
||||
print("not enough arguments\n")
|
||||
help()
|
||||
sys.exit()
|
||||
if(len(sys.argv) > 4):
|
||||
print("too many arguments\n")
|
||||
help()
|
||||
sys.exit()
|
||||
|
||||
if(sys.argv[1].isdecimal):
|
||||
val1=int(sys.argv[1])
|
||||
|
||||
else:
|
||||
print("1st arg should be an integer!")
|
||||
help()
|
||||
sys.exit()
|
||||
if(sys.argv[2].isascii and len(sys.argv[2]) == 1):
|
||||
if (not ((sys.argv[2]=="+") or (sys.argv[2]=="-") or (sys.argv[2]==".") or (sys.argv[2]=="/"))):
|
||||
print("2nd arg should be an operator [ + - . / ]!\n")
|
||||
help()
|
||||
sys.exit()
|
||||
op=sys.argv[2]
|
||||
|
||||
if(sys.argv[3].isdecimal):
|
||||
val2=int(sys.argv[3])
|
||||
else:
|
||||
print("3rd arg should be an integer!")
|
||||
help()
|
||||
|
||||
|
||||
#todo switch case and then operations
|
||||
|
||||
if(op=="+"):
|
||||
print(f"{val1} + {val2} = {val1+val2}")
|
||||
|
||||
elif(op=="-"):
|
||||
print(f"{val1} - {val2} = {val1-val2}")
|
||||
|
||||
elif(op=="."):
|
||||
print(f"{val1} . {val2} = {val1*val2}")
|
||||
|
||||
elif(op=="/"):
|
||||
print(f"{val1} / {val2} = {val1/val2}")
|
||||
|
||||
else:
|
||||
print(f"'{op}' is not a valid operator")
|
||||
sys.exit()
|
||||
|
Loading…
Reference in New Issue