Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* levelezősök
  + Adator. prog.
  + feladatsor
  + quick link

teaching assets


Félévek

* 2024/25/1
* 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