Computer science work?

Hi, I'm currently working on a computer science thesis and I'm completely desperate about this task. It would be very nice if someone could help me 🙂

Write a function that divides two numbers. Add the required lines of code that read two variables and call the function to divide them. Print the result. Write the appropriate Python/pseudocode.

Thanks

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
9 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Dultus, UserMod Light
def divide_numbers(num1, num2): if num2 == 0: return "Error: Division by zero!" else: return num1 / num2 # Eingabe von zwei Zahlen num1 = float(input("Bitte geben Sie die erste Zahl ein: ")) num2 = float(input("Bitte geben Sie die zweite Zahl ein: ")) # Aufruf der Funktion, um die Zahlen zu dividieren ergebnis = divide_numbers(num1, num2) # Ausgabe des Ergebnisses print("Das Ergebnis der Division ist: ", ergebnis)

That's what I'd do. In particular, check whether the second number is 0 because we otherwise throw an exception.

Dultus, UserMod Light
Reply to  Nic1400

Didn't write a pseudocode forever. You may look like this or something similar:

 Funktion divide_numbers(num1, num2) Wenn num2 gleich 0 ist, dann Gib "Fehler: Division durch Null!" zurück Sonst, Gib num1 geteilt durch num2 zurück Ende Wenn Ende Funktion Hauptprogramm: Gib "Bitte geben Sie die erste Zahl ein: " aus Lese num1 ein als Gleitkommazahl Gib "Bitte geben Sie die zweite Zahl ein: " aus Lese num2 ein als Gleitkommazahl ergebnis = divide_numbers(num1, num2) Gib "Das Ergebnis der Division ist: " zusammen mit ergebnis aus Ende Hauptprogramm
Robbenklatscher
1 year ago

should fit

Robbenklatscher
1 year ago
Reply to  Nic1400

no ding

Robbenklatscher
1 year ago
Reply to  Nic1400

Jo here, I hope that’s what you meant

Function divide_numbers(a,b):

if b is 0:

return “Bug: Division by Zero!”

Other:

give a divided by b back

Main program:

Input num1

Input num2

result = divide_numbers(num1, num2)

“The result of the division is:” result