Challenge: Preventing Code Injection
Tehtävä
Swipe to start coding
Refactor a function that previously used eval() to perform mathematical operations based on a string input, so that it cannot be exploited for code injection. Use only a dictionary of explicitly allowed operations.
- Only allow the operations "add", "subtract", "multiply", and "divide".
- For each allowed operation, perform the corresponding arithmetic on
aandb. - If an operation is not allowed, return
None. - For division, if
bis zero, returnNone.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 1. Luku 5
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 5.56
Challenge: Preventing Code Injection
Pyyhkäise näyttääksesi valikon
Tehtävä
Swipe to start coding
Refactor a function that previously used eval() to perform mathematical operations based on a string input, so that it cannot be exploited for code injection. Use only a dictionary of explicitly allowed operations.
- Only allow the operations "add", "subtract", "multiply", and "divide".
- For each allowed operation, perform the corresponding arithmetic on
aandb. - If an operation is not allowed, return
None. - For division, if
bis zero, returnNone.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 1. Luku 5
single