Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

* Scripting Languages
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* aktuális (2023/24/2)
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

20121120b

Exceptions#2

Consider the following script. The program reads two numbers from the user, divides the first number with the second, and prints the result.

#!/usr/bin/env python3

def main():
    while True:
        num1 = float(input("Number A: "))
        num2 = float(input("Number B: "))
        result = num1 / num2
        print('Result of the division: {0:.2f}'.format(result))
        print('-' * 10)

#####

if __name__ == "__main__":
    main()

Exercise

Complete the program above to treat the following cases:

  • If the user didn't specify a number, then print an error message that tells the user (s)he should provide a number.
  • If we want to quit with CTRL+C or CTRL+D, don't produce any error message.
  • If the user wants to divide by 0, print an informative error message.

Advance step by step. Work on one case and test it. If it's OK, move on to the next one.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2017 August 03, 23:55