Browse Source

files

master
Ken Schaefer 8 months ago
parent
commit
0940336668
  1. 79
      basics/basics.py
  2. 6
      basics/hello.py
  3. 19
      basics/io.py

79
basics/basics.py

@ -0,0 +1,79 @@
import random
# Hello World
print ('Hello World!')
print ('What is your name?')
myName = input()
print ('It is good to meet you ' + myName)
print ('The length of your name is: ')
print (len(myName));
# Conditional
if myName == 'Ken':
print('Hello')
elif myName == 'Randolph':
print('Ftaghn')
else:
print('Hi')
# Looping
spam = 0
while spam < 5:
print('Spam ')
spam = spam + 1
# Range
total = 0
for num in range(101):
total = total + num
print(total)
for i in range(5):
print(random.randint(1, 10))
# Functions
def hello(name):
print('Hello ' + name)
return 1
r = hello('Fred')
print(r)
# Exceptions
def spam(divideBy):
try:
return 42 / divideBy
except ZeroDivisionError:
print('Cant divide by 0')
# Lists
animals = ['cat', 'bat', 'rat', 'elephant']
print(animals[1])
print(animals[-1])
# Slices
atimals = animals[1:3]
print(len(atimals))
animals.append('moose')
animals.remove('rat')
animals.sort()
print(animals)
# Dictionaries
aMonster = {'size':'large', 'color':'red'}
print(aMonster['size'])
for v in aMonster.values():
print(v)

6
basics/hello.py

@ -1,6 +0,0 @@
print ('Hello World!')
print ('What is your name?')
myName = input()
print ('It is good to meet you ' + myName)
print ('The length of your name is: ')
print (len(myName));

19
basics/io.py

@ -0,0 +1,19 @@
import os
# Current working directory
home = os.getcwd()
print(home)
# Change directory
os.chdir('C:\\Windows\\System32')
print(os.getcwd())
os.chdir(home)
print(os.getcwd())
# Create folders
os.makedirs('./files')
Loading…
Cancel
Save