diff --git a/source/week-1/print/input.py b/source/week-1/print/input.py index b840e8b..251ee73 100644 --- a/source/week-1/print/input.py +++ b/source/week-1/print/input.py @@ -1,6 +1,12 @@ -# The input funciton allows you to prompt the user for a value +# The input function allows you to prompt the user to type something # You need to declare a variable to hold the value entered by the user -Name = input('What is your name? ') +# IMPORTANT: When you declare a variable, it has to start with small letter +name = input('What is your name? ') -print('Great, your name is '+ Name) \ No newline at end of file +print('Great, your name is ' + name) + +# The user can type their name on the next line with the \n command / not on the same line as above +name = input("What is your name?\n") + +print('Great, your name is ' + name) diff --git a/source/week-1/print/print.py b/source/week-1/print/print.py index ec50927..8b8ce73 100644 --- a/source/week-1/print/print.py +++ b/source/week-1/print/print.py @@ -5,7 +5,10 @@ print('Hello world single quotes') # Strings can also be enclosed in double quotes -print("Hello world double quotes") +print("Hello world - double quotes") -# using print to display integers -print(188) \ No newline at end of file +# using print to display integer / whole numbers +print(188) + +# using print to display float number / real number +print(99.9) diff --git a/source/week-1/variables/doing_math.py b/source/week-1/variables/doing_math.py index 886a322..34acdbb 100644 --- a/source/week-1/variables/doing_math.py +++ b/source/week-1/variables/doing_math.py @@ -3,7 +3,8 @@ first_num = 6 second_num = 2 -# You can peform a variety of math operations on numeric values +# FIRST WAY OF DOING IT +"""# You can perform a variety of math operations on numeric values print('addition') print(first_num + second_num) print('subtraction') @@ -14,3 +15,29 @@ print(first_num / second_num) print ('exponent') print(first_num ** second_num) +""" + +# SECOND WAY OF DOING IT + +# importing operator module +import operator + +# using add() to add two numbers +print("The addition of numbers is :", end="") +print(operator.add(first_num, second_num)) + +# using sub() to subtract two numbers +print("The difference of numbers is :", end="") +print(operator.sub(first_num, second_num)) + +# using mul() to multiply two numbers +print("The multiplication of numbers is :", end="") +print(operator.mul(first_num, second_num)) + +# using truediv() to divide two numbers +print("The division of numbers is :", end="") +print(operator.truediv(first_num, second_num)) + +# using pow() to find the power of two numbers +print("The power of numbers is :", end="") +print(operator.pow(first_num, second_num)) diff --git a/source/week-1/variables/format_strings.py b/source/week-1/variables/format_strings.py index 6b79588..a6551d3 100644 --- a/source/week-1/variables/format_strings.py +++ b/source/week-1/variables/format_strings.py @@ -1,8 +1,21 @@ +# FIRST WAY +# the capitalize function will return the string with +# the first letter uppercase and the rest of the word lowercase + +# Ask the user for their first and last name // it does not matter how the user types it: +# ALEX, alex, aLEX etc. --> it will be saved in the memory as Alex (Fist letter will be with uppercase) +first_name = input('What is your first name? ').capitalize() +last_name = input('What is your last name? ').capitalize() + +print('Hello ' + first_name + ' ' + last_name) + + +# SECOND WAY # Ask the user for their first and last name first_name = input('What is your first name? ') last_name = input('What is your last name? ') # the capitalize function will return the string with # the first letter uppercase and the rest of the word lowercase -print ('Hello ' + first_name.capitalize() + ' ' \ - + last_name.capitalize()) +print('Hello ' + first_name.capitalize() + ' ' + last_name.capitalize()) +