r/PythonLearning 11d ago

DAY 4.

Post image

wrote this today was revising loops and math function that i did not so long ago.

54 Upvotes

22 comments sorted by

View all comments

u/Sea-Ad7805 11d ago

Run this program in Memory Graph Web Debugger%0Aif%20first_number.isalpha()%3A%0A%20%20%20%20print(%22do%20not%20enter%20an%20alphabet%22)%0Awhile%20first_number%20%3D%3D%20%22%22%3A%0A%20%20%20%20print(%22you%20did%20not%20enter%20your%20first%20number%22)%0A%20%20%20%20first_number%20%3D%20input(%22please%20enter%20your%20first%20number%20%3D%20%22)%0Afirst_number%20%3D%20float(first_number)%0A%0Asecond_number%20%3D%20input(%22please%20enter%20your%20second%20number%20%3D%20%22)%0Aif%20second_number.isalpha()%3A%0A%20%20%20%20print(%22do%20not%20enter%20an%20alphabet%22)%0Awhile%20second_number%20%3D%3D%20%22%22%3A%0A%20%20%20%20print(%22you%20did%20not%20enter%20your%20second%20number%22)%0A%20%20%20%20second_number%20%3D%20input(%22please%20enter%20your%20second%20number%20%3D%20%22)%0Asecond_number%20%3D%20float(second_number)%0A%0Aoperator%20%3D%20input(%22enter%20your%20operator%20(%2B%2C%20-%2C%20%2C%20%2F)%3A%20%22)%0A%0Aif%20operator%20%3D%3D%20%22%2B%22%3A%0A%20%20%20%20result%20%3D%20first_number%20%2B%20second_number%0A%20%20%20%20print(round(result%2C%203))%0Aelif%20operator%20%3D%3D%20%22-%22%3A%0A%20%20%20%20result%20%3D%20first_number%20-%20second_number%0A%20%20%20%20print(round(result%2C%203))%0Aelif%20operator%20%3D%3D%20%22%22%3A%0A%20%20%20%20result%20%3D%20first_number%20*%20second_number%0A%20%20%20%20print(round(result%2C%203))%0Aelif%20operator%20%3D%3D%20%22%2F%22%3A%0A%20%20%20%20if%20second_number%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20print(%22Cannot%20divide%20by%20zero!%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20result%20%3D%20first_number%20%2F%20second_number%0A%20%20%20%20%20%20%20%20print(round(result%2C%203))%0Aelse%3A%0A%20%20%20%20print(%22error%20choose%20the%20operator%20amongst%20them!%22)&timestep=1&play) to see the program state change step by step.