鱼C论坛

 找回密码
 立即注册
查看: 2687|回复: 5

python3新人求助,我写了一个小程序但是有点小问题,求大神帮助

[复制链接]
发表于 2016-10-13 10:35:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 thyx 于 2016-10-13 10:39 编辑

import random

def perform_t(a, b):

    rate = float(b)

    if a == 0:
        for i in range(num):
            x =  random.randint(0,10)
            y =  random.randint(0,10)
            z = x + y

            print (x, '+', y, '=',z1)                (这里有点小问题,应该怎么写,用户输入进去的值和标准答案作比较,应该怎么比较,下面z2也是同样的问题)
            if z1 != z:
                print( 'Incorrect - the answer is', z)
                rate = rate - 1

    elif a == 1:
        for i in range(num):
            x =  random.randint(0,10)
            y =  random.randint(0,10)
            z = x * y

            print (x, '*', y, '=',z2)
            if z2 != z:
                print ('Incorrect - the answer is', z)
                rate = rate - 1

    return rate

print ('Welcome to addition / multiplication test')
print( '\nHow mant questions would you like to be tested on?')
num = int(input ('Enter a non negative integer for the answer:'))

if num == 0:
    print( 'goodbye')
else:
    print ('This software tests you with', num, 'questions ......')
    print ('0) Addition')
    print ('1) Multiplication')
    aORm = int(input('Please make a selection(0 or 1):'))
    rate = perform_t(aORm, num)
    if rate/num >= 0.8:
        print ('well done')
    elif rate/num < 0.6:
        print ('please study more')
    else:
        print ('not too bad')


下面两张图是例子
3124213.jpg
12421321.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-10-13 12:53:48 | 显示全部楼层
把print (x, '+', y, '=',z1)  改为 z1 = int(input('%d + %d = '%(x, y)))
z2也一样改
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-10-13 21:17:54 | 显示全部楼层
冬雪雪冬 发表于 2016-10-13 12:53
把print (x, '+', y, '=',z1)  改为 z1 = int(input('%d + %d = '%(x, y)))
z2也一样改

import random

def perform_t(a, b):
    rate = b
    if a == 0:
        for i in range(num):
            x =  random.randint(0,10)
            y =  random.randint(0,10)
            z = x + y
            print (x, '+', y, '=')
            z1 = int(input())
            if z1 != z:
                print( 'Incorrect - the answer is', z)
                rate = rate - 1

    elif a == 1:
        for i in range(num):
            x =  random.randint(0,10)
            y =  random.randint(0,10)
            z = x * y
            print (x, '*', y, '=')
            z2 = int(input())
            if z2 != z:
                print ('Incorrect - the answer is', z)
                rate = rate - 1
    return rate

print ('Welcome to addition / multiplication test')
print( 'How mant questions would you like to be tested on?')
num = int(input ('Enter a non negative integer for the answer:'))

if num == 0:
    print( 'goodbye')
else:
    print ('This software tests you with', num, 'questions ......')
    print ('0) Addition')
    print ('1) Multiplication')
    r = int(input('Please make a selection(0 or 1):'))
    rate = perform_t(r, num)
    if rate/num >= 0.8:
        print ('well done')
    elif rate/num < 0.6:
        print ('please study more')
    else:
        print ('not too bad')
我改成这样了,现在是可以了,但是你输入结果是在下一行,不在算式的同一行,怎么办,谢谢
10 * 2 =
20
0 * 6 =
0
7 * 6 =
42
7 * 0 =
0
well done
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-10-14 08:36:15 | 显示全部楼层
thyx 发表于 2016-10-13 21:17
import random

def perform_t(a, b):

方法1:像我上面的帖子,把print的内容放在input中。
方法2:把print (x, '+', y, '=')改为print (x, '+', y, '=', end = '')
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-10-15 23:14:29 | 显示全部楼层
冬雪雪冬 发表于 2016-10-14 08:36
方法1:像我上面的帖子,把print的内容放在input中。
方法2:把print (x, '+', y, '=')改为print (x, '+ ...

谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-10-31 12:26:07 | 显示全部楼层
感謝樓主提問
學習到很多
原來一個結果可以用很多方式來處理
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-23 08:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表