python 除数为0_Python中防止程序运行的零除法

我还在为我的多项选择测验项目而辛苦工作。我快到了。只有几个虫子还没解决。这个程序会记录你得到的正确的,错误的,以及当前的百分比。但是,我的程序不会运行,因为最初,用户没有回答任何问题。因此,它们的正确率为NULL%。我的代码如下:import random

import sys

import os

import math

right_answer_total = float(0)

wrong_answer_total = float(0)

answer_total = float(right_answer_total + wrong_answer_total)

percentage = 100 * (float(right_answer_total) / float(answer_total))

word_drills = {'class': 'Tell Python to make a new kind of thing.',

'object': 'Two meanings: the most basic kind of thing, and any instance of some thing.',

'instance': 'What you get when you tell Python to create a class.',

'def': 'How you define a function inside a class.',

'self': 'Inside the functions in a class, self is a variable for the instance/object being


版权声明:本文为weixin_32191249原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。