diff --git a/basics/basics.py b/basics/basics.py new file mode 100644 index 0000000..092a321 --- /dev/null +++ b/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) + + \ No newline at end of file diff --git a/basics/hello.py b/basics/hello.py deleted file mode 100644 index eadc6e5..0000000 --- a/basics/hello.py +++ /dev/null @@ -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)); \ No newline at end of file diff --git a/basics/io.py b/basics/io.py new file mode 100644 index 0000000..54c5570 --- /dev/null +++ b/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') +