Skip to content

Commit 77febbd

Browse files
committed
QuickLab-1 Working with Python Scripts Completed
1 parent db9f139 commit 77febbd

6 files changed

+60
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import shutil
2+
import psutil
3+
4+
def check_disk_usage(disk):
5+
du = shutil.disk_usage(disk)
6+
free = du.free/du.total *100
7+
return free>20
8+
def check_cpu_usage():
9+
usage = psutil.cpu_percent(1)
10+
return usage<75
11+
12+
if not check_disk_usage("/") or not check_cpu_usage():
13+
print("ERROR!")
14+
else:
15+
print("Everything is OK!")

create_file.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env pyhton3
2+
3+
import os
4+
import sys
5+
6+
filename=sys.argv[1]
7+
8+
if not os.path.exists(filename):
9+
with open(filename, "w") as f:
10+
f.write("New file created\n")
11+
else:
12+
print("Error, the file {} already exists!".format(filename))
13+
sys.exit(1)

hello.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python3
2+
name = input("Please enter your name: ")
3+
print("hello, " + name)
4+

parameters.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
print(sys.argv)
5+

seconds.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python3
2+
3+
def to_seconds(hours, minutes, seconds):
4+
return hours*3600+minutes*60+seconds
5+
print("welcome to this time converter")
6+
7+
cont = "y"
8+
while(cont.lower() == "y"):
9+
hours = int(input("Enter the number of hours: "))
10+
minutes =int(input("Enter the numbers of minutes: "))
11+
seconds = int(input("Enter the number of seconds: "))
12+
13+
print("That's {} seconds" .format(to_seconds(hours, minutes, seconds)))
14+
print()
15+
cont = input("Do you want to do another conversion? [y to continue] ")
16+
print("Good bye!")

variables.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
5+
print("HOME: " + os.environ.get("HOME", ""))
6+
print("SHELL:" + os.environ.get("SHELL", ""))
7+
print("FRUIT: " + os.environ.get("FRUIT", ""))

0 commit comments

Comments
 (0)