Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,787 members, 7,810,051 topics. Date: Friday, 26 April 2024 at 07:30 PM

My Collections Of Python Projects - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / My Collections Of Python Projects (3548 Views)

2020 Fundamentals Of Python Programming Thread #1 (WITH PROJECTS) / How Can I Get “30 Days Of Python” Tutorial / Benefits Of PYTHON Programming As Career For Everyone Interested In IT Success (2) (3) (4)

(1) (2) (3) (4) (Reply) (Go Down)

Re: My Collections Of Python Projects by KlausMichaelson: 10:21pm On Jul 30, 2020
Akhigbeblog:

Do you have link which I can use to to download the videos from?

No sir I don't. But why not try YouTube videos??
Mosh Hamedani on YouTube did a 6hr+ video on python. You'll love it!
Re: My Collections Of Python Projects by 3KINGZ18: 10:28pm On Jul 30, 2020
Patiee:
Excuse me, I'm out of the topic. Does anybody here know how long it takes for the openWeather API keys to be activated. They emailed me that it will take a couple of hours and it has been a day now
Pls look for another weather api to use openWeather always throws in a cors error and no-cors can't even fix it.
Check out darksky api
Re: My Collections Of Python Projects by Akhigbeblog(m): 11:22pm On Jul 30, 2020
KlausMichaelson:


No sir I don't. But why not try YouTube videos??
Mosh Hamedani on YouTube did a 6hr+ video on python. You'll love it!
Aiit I'll, thanks so much
Re: My Collections Of Python Projects by ibromodzi: 11:22pm On Jul 30, 2020
KlausMichaelson:


Good evening Sir

Your question:
What tells the user the kind of operations your program is capable of performing?

My Answer:
Calculation = input('addition, subtraction, multiplication, division, or modulo? ')

Your Question:
What happens if the user does not enter the operations to be performed correctly as used in the program? Like Addition instead of addition (issue of cases).

My Answer:
I use .lower if I want any input to be in lower case i.e
Calculation = input('addition, subtraction, multiplication, division, or modulo? ').lower

Your Question:
What happens if the user tries to divide a number by zero?

My Answer:
You use try except ZeroDivisionError or ValueError

But Sir I don't know where to to put in this try, except block in my program sad

The reason why I am yet to update my new code after about an hour now is because I don't know the position where the try..... except ZeroDivisionError and except ValueError block comes in. Please help me sir.

Thank you





def operation():

'''
You start the top of the program with while loop
purpose: the program executes once and then checks if all condition are satisfied
if no error is encounterd, the program perform its function and end
else the while loop runs again and agin untill no error is encountered

Let me know if there's anything you don't get
'''
while True:
x = int(input('Enter a number '))
y = int(input('Enter another number '))
calculation = input(f"'You can eiher enter addition, subtraction, multiplication"
f" or division to perform an operation'"wink.lower()

if calculation == 'addition':
print(f"result is {x+y}"wink

elif calculation == 'subtraction':
print(f"result is {x-y}"wink

elif calculation == 'multiplication':
print(f"result is {x*y}"wink

elif calculation == 'division':
'''
this is where exception handling goes
'''
try:
'''
the next block first checks if the result has no remainder (modulus) i.e an integer
if the number has no remainder, you get the result of the division printed
else you print the result along with the modulus
I prefer to include this here instead of having it as a seperate calculation
'''
if x % y == 0:
print(f"result is {x/y}"wink
else:
print(f"result is {x/y} remainder {x%y}"wink

'''
You break the while loop if the above condtions run with no error
else, the user is forced to re enter the value again i.e the loop starts all over
'''
break

except ZeroDivisionError:
print ("can not divide by zero, enter a denominator other than zero"wink
except ValueError:
print ("Invalid parameter"wink
operation() #just call the function



Replace the emojis with closing brackets

2 Likes

Re: My Collections Of Python Projects by KlausMichaelson: 3:20am On Jul 31, 2020
ibromodzi:




def operation():

'''
You start the top of the program with while loop
purpose: the program executes once and then checks if all condition are satisfied
if no error is encounterd, the program perform its function and end
else the while loop runs again and agin untill no error is encountered

Let me know if there's anything you don't get
'''
while True:
x = int(input('Enter a number '))
y = int(input('Enter another number '))
calculation = input(f"'You can eiher enter addition, subtraction, multiplication"
f" or division to perform an operation'"wink.lower()

if calculation == 'addition':
print(f"result is {x+y}"wink

elif calculation == 'subtraction':
print(f"result is {x-y}"wink

elif calculation == 'multiplication':
print(f"result is {x*y}"wink

elif calculation == 'division':
'''
this is where exception handling goes
'''
try:
'''
the next block first checks if the result has no remainder (modulus) i.e an integer
if the number has no remainder, you get the result of the division printed
else you print the result along with the modulus
I prefer to include this here instead of having it as a seperate calculation
'''
if x % y == 0:
print(f"result is {x/y}"wink
else:
print(f"result is {x/y} remainder {x%y}"wink

'''
You break the while loop if the above condtions run with no error
else, the user is forced to re enter the value again i.e the loop starts all over
'''
break

except ZeroDivisionError:
print ("can not divide by zero, enter a denominator other than zero"wink
except ValueError:
print ("Invalid parameter"wink
operation() #just call the function



Replace the emojis with closing brackets

Sir I am very sorry to not have brought this to your notice. I really feel Happy having you around Sir. I have to force myself up this early morning to rewrite my code especially the area you brought in the try.... except ZeroDivisionError. I have tried using it in my code before now, but I just didn't know where to bring it in. Thanks a lot for the clarification.

Although I didn't use while loop, I was able to still use the if and elif. Sir your corrections are welcomed gladly.
Sir check my updated Post to see my new code
Re: My Collections Of Python Projects by KlausMichaelson: 3:35am On Jul 31, 2020
ibromodzi:


Alright..... You are welcome sir.

You may add an extra bonus by implementing your solution in OOP (not necessary though).
Cheers!

Sir I have updated my Code. Thanks a lot.
Re: My Collections Of Python Projects by KlausMichaelson: 3:36am On Jul 31, 2020
Akhigbeblog:

Aiit I'll, thanks so much

You're welcome sir
Re: My Collections Of Python Projects by KlausMichaelson: 3:37am On Jul 31, 2020
Taofeekdboy:
I am through for the day as it is very late here, I would have shown you the code but you have to change the logic if you want to use the try and exept block.
I recommend while loop, if it's true, then it will keep requesting for the user's input if there's an error until you put a condition to meet.
Read more on while loop, try and exeption. As a beginner, try to fix things on your own, when you reach that point you feel you are lost then you can Google or use stackoverflow. Goodnight.

Sir I have updated my Code. Thank you very much.
Re: My Collections Of Python Projects by ibromodzi: 4:33am On Jul 31, 2020
KlausMichaelson:


Sir I am very sorry to not have brought this to your notice. I really feel Happy having you around Sir. I have to force myself up this early morning to rewrite my code especially the area you brought in the try.... except ZeroDivisionError. I have tried using it in my code before now, but I just didn't know where to bring it in. Thanks a lot for the clarification.

Although I didn't use while loop, I was able to still use the if and elif. Sir your corrections are welcomed gladly.
Sir check my updated Post to see my new code

Well done! Keep it up....we are all learning

1 Like

Re: My Collections Of Python Projects by KlausMichaelson: 7:17am On Jul 31, 2020
ibromodzi:

Well done! Keep it up....we are all learning
Thank you Sir
Re: My Collections Of Python Projects by aerozac(m): 5:15pm On Jul 31, 2020
You can check though this code
num_one = float(input("Plese input your first number.... "wink)
calculation = input("Please input the operand you want.... "wink.lower() # add, subtract, multiply, divide, power, percent, modulo
num_two = float(input("Plese input your second number.... "wink)

def operation(num_one, num_two):

if calculation == "divide" and num_two == 0:
print("Error"wink
elif calculation == "power" and num_one == 0:
print("Error"wink
elif calculation == "add":
sum = num_one + num_two
print(sum)
elif calculation == "subtract":
sub = num_one - num_two
print(sub)
elif calculation == "multiply":
multi = num_one * num_two
print(multi)
elif calculation == "divide":
division = num_one / num_two
print(division)
elif calculation == "power":
raised = num_one**num_two
print(raised)
elif calculation == "percent":
percentage = 0.01*num_one*num_two
print(percentage)
elif calculation == "modulo":
modulus = num_one % num_two
print(modulus)
else:
pass


operation(num_one, num_two)

1 Like

Re: My Collections Of Python Projects by aerozac(m): 5:19pm On Jul 31, 2020
We are learning. I started recectly too. change the emoji to ( )
Re: My Collections Of Python Projects by fortifiedng: 5:22pm On Jul 31, 2020
KlausMichaelson:


I'll check it out sir. Thank you
You're welcome

1 Like

Re: My Collections Of Python Projects by KlausMichaelson: 7:23pm On Jul 31, 2020
aerozac:
You can check though this code
num_one = float(input("Plese input your first number.... "wink)
calculation = input("Please input the operand you want.... "wink.lower() # add, subtract, multiply, divide, power, percent, modulo
num_two = float(input("Plese input your second number.... "wink)

def operation(num_one, num_two):

if calculation == "divide" and num_two == 0:
print("Error"wink
elif calculation == "power" and num_one == 0:
print("Error"wink
elif calculation == "add":
sum = num_one + num_two
print(sum)
elif calculation == "subtract":
sub = num_one - num_two
print(sub)
elif calculation == "multiply":
multi = num_one * num_two
print(multi)
elif calculation == "divide":
division = num_one / num_two
print(division)
elif calculation == "power":
raised = num_one**num_two
print(raised)
elif calculation == "percent":
percentage = 0.01*num_one*num_two
print(percentage)
elif calculation == "modulo":
modulus = num_one % num_two
print(modulus)
else:
pass


operation(num_one, num_two)

Wow. I appreciate your time and response Sir. Thank you very much.

Sir why didn't you try using
>>>try:

>>>except ZeroDivisionError:
to avoid ZeroDivisionError when zero is used as the denominator? or did your code checkmate it?? Pls go through my own updated code.
Re: My Collections Of Python Projects by ibromodzi: 7:45pm On Jul 31, 2020
KlausMichaelson:


Wow. I appreciate your time and response Sir. Thank you very much.

Sir why didn't you try using
>>>try:

>>>except ZeroDivisionError:
to avoid ZeroDivisionError when zero is used as the denominator? or did your code checkmate it?? Pls go through my own updated code.

He's actually taken that into cognizance, albeit not in a Pythonic way..

You guys should try to work on real life problems. You can use the site someone suggested above.

1 Like

Re: My Collections Of Python Projects by KlausMichaelson: 8:35pm On Jul 31, 2020
ibromodzi:


He's actually taken that into cognizance, albeit not in a Pythonic way..

You guys should try to work on real life problems. You can use the site someone suggested above.


Alright that's cool.

Sir pls don't mind me. I'll still check out that website. It's just that I have diverted my attention to Django at the moment... This whole thing is really not easy.
Re: My Collections Of Python Projects by KlausMichaelson: 8:43pm On Jul 31, 2020
Good evening my Pros please I have a Target at the moment. I don't know if anyone has ever considered the exercise before. It goes this way;

I want to write a code that will predict a time table or roster for lesson teachers in a senior secondary school.
Each teacher must have two subjects to teach. They must also appear at least 2times/perioy in a week and the period they are to teach must not clash with their second subject in any of the lesson period. The Program should enable me prepare a time table for all the teachers' lesson period.


My head is aching me cos I've been thinking about it for quite a while now.
Re: My Collections Of Python Projects by ibromodzi: 8:40am On Aug 01, 2020
KlausMichaelson:
Good evening my Pros please I have a Target at the moment. I don't know if anyone has ever considered the exercise before. It goes this way;

I want to write a code that will predict a time table or roster for lesson teachers in a senior secondary school.
Each teacher must have two subjects to teach. They must also appear at least 2times/perioy in a week and the period they are to teach must not clash with their second subject in any of the lesson period. The Program should enable me prepare a time table for all the teachers' lesson period.


My head is aching me cos I've been thinking about it for quite a while now.

A good knowledge of data structure and algorithm should set you on the right track.
Re: My Collections Of Python Projects by KlausMichaelson: 10:10am On Aug 01, 2020
ibromodzi:


A good knowledge of data structure and algorithm should set you on the right track.

Exactly, I had the feeling it's beyond the use of Python only. Machine learning is coming to mind.

Honestly this stuffs aren't too smooth like I thought. I went through machine learning tutorial yesterday, I was introduced to Sci-kit learn and some decision trees and algorithms. I'm just stuck at so many things right now(numpy, powerbi , Django) . But there is no problem.

I have no choice than to keep learning. Thank you sir.
Re: My Collections Of Python Projects by ibromodzi: 11:14am On Aug 01, 2020
KlausMichaelson:


Exactly, I had the feeling it's beyond the use of Python only. Machine learning is coming to mind.

Honestly this stuffs aren't too smooth like I thought. I went through machine learning tutorial yesterday, I was introduced to Sci-kit learn and some decision trees and algorithms. I'm just stuck at so many things right now(numpy, powerbi , Django) . But there is no problem.

I have no choice than to keep learning. Thank you sir.

ML for this task? Nope
Data structure and algorithm ain't the same as data science.
One last thing I'll say is that you should have your goal(s) defined. You can't learn everything at a time.
Re: My Collections Of Python Projects by KlausMichaelson: 11:45am On Aug 01, 2020
ibromodzi:


ML for this task? Nope
Data structure and algorithm ain't the same as data science.
One last thing I'll say is that you should have your goal(s) defined. You can't learn everything at a time.

No be lie sad I can't learn everything at a time. I have to stick to my targets and have a defined goal. Thanks for the advice sir. I really appreciate it.
Re: My Collections Of Python Projects by Nobody: 11:56pm On Aug 02, 2020
KlausMichaelson:


No be lie sad I can't learn everything at a time. I have to stick to my targets and have a defined goal. Thanks for the advice sir. I really appreciate it.
if you are interested ,we could learn together
Re: My Collections Of Python Projects by Brukx(m): 3:52pm On Aug 03, 2020
KlausMichaelson:


Exactly, I had the feeling it's beyond the use of Python only. Machine learning is coming to mind.

Honestly this stuffs aren't too smooth like I thought. I went through machine learning tutorial yesterday, I was introduced to Sci-kit learn and some decision trees and algorithms. I'm just stuck at so many things right now(numpy, powerbi , Django) . But there is no problem.

I have no choice than to keep learning. Thank you sir.
I think you can tackle that exercise with basic python functions
Re: My Collections Of Python Projects by KlausMichaelson: 8:22pm On Aug 03, 2020
Brukx:
I think you can tackle that exercise with basic python functions


Please How possible is that??
Re: My Collections Of Python Projects by KlausMichaelson: 8:22pm On Aug 03, 2020
UnchainedAddict:
if you are interested ,we could learn together


Yes sir I want to learn.
Re: My Collections Of Python Projects by Nobody: 8:27pm On Aug 03, 2020
KlausMichaelson:



Yes sir I want to learn.
on WhatsApp or here ? just the two of us , I'm tired of pointless groups
Re: My Collections Of Python Projects by KlausMichaelson: 9:12pm On Aug 03, 2020
UnchainedAddict:
on WhatsApp or here ? just the two of us , I'm tired of pointless groups


Honestly I would have loved it but for the sake of Some persons who would be grateful to see everything here from cradle in later times,, I would want it to be done here.

Thank you for the Idea.

So sir how do we Kick off??
Honestly I thought I was an intermediate, but I need to be honest with myself, I'm still a learner
Re: My Collections Of Python Projects by ibromodzi: 8:06am On Aug 04, 2020
KlausMichaelson:


No be lie sad I can't learn everything at a time. I have to stick to my targets and have a defined goal. Thanks for the advice sir. I really appreciate it.

Challenge for you

It is possible to name the days 0 thru 6 where day 0 is Sunday and day 6 is Saturday. If you go on a wonderful holiday leaving on day number 3 (a Wednesday) and you return home after 10 nights you would return home on a Saturday (day 6). Write a general version of the program which asks for the starting day number, and the length of your stay, and it will tell you the number of day of the week you will return on.

Note: do not use any calendar module
Re: My Collections Of Python Projects by KlausMichaelson: 3:59pm On Aug 04, 2020
ibromodzi:


Challenge for you

It is possible to name the days 0 thru 6 where day 0 is Sunday and day 6 is Saturday. If you go on a wonderful holiday leaving on day number 3 (a Wednesday) and you return home after 10 nights you would return home on a Saturday (day 6). Write a general version of the program which asks for the starting day number, and the length of your stay, and it will tell you the number of day of the week you will return on.

Note: do not use any calendar module


Good day Sir. I really love this one smiley
Sorry I've been up to somethings for a while now.

My system is down at the moment. But for the main time I'll try to figure it out in my head. Thank you sir.
Re: My Collections Of Python Projects by aerozac(m): 10:27pm On Aug 04, 2020
I am following you guys carefully too. Please keep the coding challenges coming, I am learning
Re: My Collections Of Python Projects by Nobody: 11:59pm On Aug 04, 2020
Darivie04:

number1 = int(input('what number? '))
number2 = int(input('what number? '))
calculation = input('what operation do you want? ')

def operation(num1,num2):
if calculation == 'addition':
return num1 + num2
elif calculation == 'subtraction':
return num1 - num2
elif calculation == 'multiplication':
return num1 * num2
elif calculation == "division":
return num1 / num2
elif calculation == 'modulo':
return num1 % num2

print (operation(number1, number2))

A bit neater.

The guy is still a toddler naaa... he will get to function very soon.
Re: My Collections Of Python Projects by KlausMichaelson: 6:33am On Aug 05, 2020
BlaqTesla:


The guy is still a toddler naaa... he will get to function very soon.


Lols cheesy
Gbas Gbos Gbas Gbos. you've finished me sir.

I updated that code through the help of My Ogas here. The updated code is much better. Yes I'm still a toddler

(1) (2) (3) (4) (Reply)

Need School Management Software / My Purple Website / The Door-Goat-Car Logic Problem

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 69
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.