Python大作业一

Python大作业一
这学期拔尖计划又安排了一次Python课程的学习,因为之前学习过了所以就没有记录平时的编程作业,把大作业记录一下~~

在这里插入图片描述

print("姓名:小吴")
print("学号:000000")
print("班级:智能183班")
print("step 1")
print("--------------------")
def displayDictionary():
    len_dic = len(dictionary)
    if len_dic == 0:
        print("*** The dictionary is empty ***")
    else:
        print("*** Known words ****")
        for i in range(len(dictionary)):
            a = dictionary[i]
            print(a[0].ljust(20),a[1].ljust(20))

dictionary = []
displayDictionary()
dictionary = [['the','这'],['big','大'],['house','房子']]
displayDictionary()

print("-------------------")
print("姓名:小吴")
print("学号:000000")
print("班级:智能183班")
print("step 2")
print("--------------------")

flag=0
dictionary = [['the','这'],['big','大'],['house','房子']]
def translateFromEnglish(word):
    lookup(word)
    return lookup(word)
def lookup(word):
    for i in dictionary:
        if word == i[0]:
            flag=1
            return i[1]

w = translateFromEnglish('house')
print('Translation of','house','is',w)

w = translateFromEnglish('dog')
print('translation of','dog','is',w)
print("姓名:小吴")
print("学号:000000")
print("班级:智能183班")
print("step 3")
print("--------------------")

def main():
    while True:
        flag = 0
        reply = input("Eng: > ")
        if reply == '?':
            displayDictionary()
        else:
            translateReply = []
            words = list(reply.strip('.,?').split(' '))
            for word in words:
                translation = lookup(word.lower())
                translateReply.append(translation)
                if translation == None:
                    print('None')
                    flag = 1
                    break
            if flag == 0:
                str1 = ' '.join(translateReply)
                if words[0] in ['what','where','why','how','is']:
                    m='?'
                else:
                    m='.'
                print(str1.capitalize()+m)
        if flag ==1:
            break

dictionary = [['the','la'],['red','resso'],['is',"e'"],['table','tavola']]

def translateFromEnglish(word):
    lookup(word)
    return lookup(word)
def lookup(word):
    for i in dictionary:
        if word == i[0]:
            #flag = 1
            return i[1]

def displayDictionary():
    len_dic = len(dictionary)
    if len_dic == 0:
        print("*** The dictionary is empty ***")
    else:
        print("*** Known words ****")
        for i in range(len(dictionary)):
            a = dictionary[i]
            print(a[0].ljust(10),a[1].ljust(10))

main()
print("姓名:小吴")
print("学号:000000")
print("班级:智能183班")
print("step 4")
print("--------------------")

def main():
    global dictionary
    while True:
        flag = 0
        reply = input("Eng: > ")
        if reply == '?':
            displayDictionary()
        else:
            translateReply = []
            words = list(reply.strip('.,?').split(' '))
            for word in words:
                translation = lookup(word.lower())
                if translation == None:
                    print('How do i translate',word,':')
                    tran1=input()
                    dictionary = dictionary+[[word,tran1]]
                    translateReply.append(tran1)
                    #flag = 1
                    #break
                else:
                    translateReply.append(translation)

            if flag == 0:
                str1 = ' '.join(translateReply)
                if words[0] in ['what','where','why','how','is']:
                    m='?'
                else:
                    m='.'
                print(str1.capitalize()+m)
        if flag ==1:
            break

dictionary = [['the','la'],['red','resso'],['is',"e'"],['table','tavola']]
def translateFromEnglish(word):
    lookup(word)
    return lookup(word)
def lookup(word):
    for i in dictionary:
        if word == i[0]:
            #flag = 1
            return i[1]

def displayDictionary():
    len_dic = len(dictionary)
    if len_dic == 0:
        print("*** The dictionary is empty ***")
    else:
        print("*** Known words ****")
        for i in range(len(dictionary)):
            a = dictionary[i]
            print(a[0].ljust(10),a[1].ljust(10))

main()
print("姓名:小吴")
print("学号:000000")
print("班级:智能183班")
print("step 5")
print("--------------------")

#从txt文件中获取字典

dict = open('dictionary.txt','r+')
dictionary = list(dict)
#print(dictionary)

#将读取到的内容排列成正常格式

for i in range(len(dictionary)):
    dic1 = dictionary[i]
    flag = 0
    for j in dic1:
        if j == '/':
            flag = 1
    if flag == 0:
        raise Exception("程序运行错误")
    dic1 = dic1.strip('\n').split('/')
    #print(dic1)
    dictionary[i] = dic1

#main()函数
def main():
    global dictionary
    while True:
        flag = 0
        reply = input("Eng: > ")
        if reply == '?':
            displayDictionary()

        #让程序可以正常结束
        elif reply == 'break1':
            break

        else:
            translateReply = []
            words = list(reply.strip('.,?').split(' '))
            for word in words:
                translation = lookup(word.lower())
                if translation == None:
                    print('How do i translate',word,':')
                    tran1=input()
                    dictionary = dictionary+[[word,tran1]]
                    #将原始列表中没有的词加到txt文件中
                    wri = word + '/' + tran1
                    dict.write(wri)
                    translateReply.append(tran1)
                    #flag = 1
                    #break
                else:
                    translateReply.append(translation)

            if flag == 0:
                str1 = ' '.join(translateReply)
                if words[0] in ['what','where','why','how','is']:
                    m='?'
                else:
                    m='.'
                print(str1.capitalize()+m)

#dictionary = [['the','la'],['red','resso'],['is',"e'"],['table','tavola']]
def translateFromEnglish(word):
    lookup(word)
    return lookup(word)
def lookup(word):
    for i in dictionary:
        if word == i[0]:
            #flag = 1
            return i[1]

def displayDictionary():
    len_dic = len(dictionary)
    if len_dic == 0:
        print("*** The dictionary is empty ***")
    else:
        print("*** Known words ****")
        for i in range(len(dictionary)):
            a = dictionary[i]
            print(a[0].ljust(10),a[1].ljust(10))

main()

'''for i in range(len(dictionary)):
    wri = dictionary[i]
    wri = wri[0]+'/'+wri[1]
    if i < len(dictionary):
        wri = wri +'\n'
    dict.write(wri)
'''
#dict.write(dictionary)
dict.close()

print("姓名:小吴")
print("学号:000000")
print("班级:智能183班")
print("step 6")
print("--------------------")

#从txt文件中获取字典

dict = open('dictionary.txt','r+')
dictionary = list(dict)
#print(dictionary)

#将读取到的内容排列成正常格式

for i in range(len(dictionary)):
    dic1 = dictionary[i]
    flag = 0
    for j in dic1:
        if j == '/':
            flag = 1
    if flag == 0:
        raise Exception("程序运行错误")
    dic1 = dic1.strip('\n').split('/')
    #print(dic1)
    dictionary[i] = dic1

#main()函数
def main():
    global dictionary
    while True:
        flag = 0
        reply = input("Eng: > ")
        if reply == '?':
            displayDictionary()

        #让程序可以正常结束
        elif reply == '*save':
            dict.seek(0)
            dict.truncate()
            save1 = []
            for i in range(len(dictionary)):
                wri = dictionary[i]
                save1 = save1 + [wri]
                wri = wri[0] + '/' + wri[1]
                if i < len(dictionary):
                    wri = wri + '\n'
                dict.write(wri)
        elif reply == '*quit':
            for  i in range(len(dictionary)):
                if dictionary[i] in save1:
                    pass
                else:
                    print(dictionary[i],'not in the dictionary,do you want to save it?')
                    result = input("Yes or No?>")
                    if result == 'Yes':
                        wri = dictionary[i]
                        wri = wri[0] + '/' + wri[1]+'\n'
                        dict.write(wri)
            break

        else:
            translateReply = []
            words = list(reply.strip('.,?').split(' '))
            for word in words:
                translation = lookup(word.lower())
                if translation == None:
                    print('How do i translate',word,':')
                    tran1=input()
                    dictionary = dictionary+[[word,tran1]]
                    translateReply.append(tran1)
                    #flag = 1
                    #break
                else:
                    translateReply.append(translation)

            if flag == 0:
                str1 = ' '.join(translateReply)
                if words[0] in ['what','where','why','how','is']:
                    m='?'
                else:
                    m='.'
                print(str1.capitalize()+m)

#dictionary = [['the','la'],['red','resso'],['is',"e'"],['table','tavola']]
def translateFromEnglish(word):
    lookup(word)
    return lookup(word)
def lookup(word):
    for i in dictionary:
        if word == i[0]:
            #flag = 1
            return i[1]

def displayDictionary():
    len_dic = len(dictionary)
    if len_dic == 0:
        print("*** The dictionary is empty ***")
    else:
        print("*** Known words ****")
        for i in range(len(dictionary)):
            a = dictionary[i]
            print(a[0].ljust(10),a[1].ljust(10))

main()





#dict.write(dictionary)
dict.close()

水平有限,还请各位大佬批评指正~~

  • 7
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
python大作业 一、Turtle创意大PK 自拟题目,完成一个利用Python程序的创意绘图,采用turtle库绘图为主,不少于50行代码,可选采用其他库。 (滑稽绘制) 二、程序练习 2.1 问题描述(10分) 人们常常提到"一万小时定律",就是不管你做什么事情,只要坚持一万小时,应该都可以成为该领域的专家。那么,10000小时是多少年多少天呢? 2.2 问题描述(10分)0380031003800341590145037657 编写计算从n到m和的函数‬,函数名为sum(n,m)‬,函数返回值为n到m所有数据的和‬,使用该函数计算输入数据x,y之间所有数据的和。 2.3 问题描述(15分) 编写函数judgeTri(a,b,c),判断以参数a,b,c的值为边长能否构成三角形并判断三角形的形状;若是锐角三角形,返回R;若是直角三角形,返回Z;若是钝角三角形,返回D;若三边长不能构成三角形,返回ERROR。 2.4 问题描述(15分) 用户输入一个字符串,分别统计其中小写字母、大写字母、数字、空格和其他字符的个数,并在一行内输出小写字母、大写字母、数字、空格和其他字符的个数。 2.5 问题描述(20分) 程序的功能: (1) 使用随机库功能,生成一个包含10个不重复且小于200的正整数列表ls1,输出ls1。‬ (2) 使用列表排序方法,对ls1按奇数在前偶数在后,并且奇数之间的相对顺序不变,偶数之间的相对顺序也不变进行排序,再输出ls1。‬ (3) 使用列表排序方法,对ls1按元素字符长度降序进行排序,输出ls1。
### 回答1: 西工大python大作业是指西安工业大学的计算机科学与技术专业学生所完成的一个关于python编程的综合性项目。这个大作业旨在提供学生们运用所学的python知识,解决实际问题的实践平台。 在西工大python大作业中,学生们可以选择不同的主题和方向,比如Web开发、数据分析、人工智能等等。学生们可以根据自己的兴趣和专业方向选择合适的主题,并根据要求完成一个完整的python项目。 在完成这个大作业过程中,学生们需要进行需求分析、系统设计、编码实现等多个阶段。他们需要学习和掌握各种python库和工具,比如Django、Flask、TensorFlow等,用于构建他们的项目。 西工大python大作业的评分标准主要包括项目的功能完整性、代码质量、创新性以及文档的完整度等方面。学生们需要展示他们的项目能够解决实际问题,并且能够在实际应用中发挥作用。 通过参加西工大python大作业,学生们可以提高他们的python编程能力和项目开发能力。他们将在实践中学习到很多实用的技能,并且提升解决问题的能力。此外,这也是一个展示自己才华和创造力的机会,对于以后的工作和学习都有着重要的意义。 总之,西工大python大作业是一个促使学生们运用所学知识解决实际问题的重要平台。通过完成这个大作业,学生们能够提升自己的编程能力,增加实践经验,并展示自己的创造力和才华。 ### 回答2: 西安工业大学Python大作业是指在学习Python编程语言的过程中,学生需要完成的一项较为复杂的设计、开发任务。 这个大作业通常涉及到多个方面的知识和技能,比如基本的语法和编程概念、面向对象编程、函数和模块的使用、数据结构和算法等。通过完成这个大作业,学生可以提高自己的编程能力和问题解决能力。 在西安工业大学Python大作业中,学生通常需要根据指定的题目或要求,设计并开发一个Python程序。这个程序可能需要实现某种功能,比如数据处理、图像处理、模拟仿真、网站开发等。学生需要根据自己的实际情况,选择合适的开发工具和技术,编写代码并进行调试、测试,最终完成一个能够正常运行的程序。 在完成这个大作业的过程中,学生还需要学习和运用一些相关的知识和技能,比如通过查找文档和参考资料解决问题、学会使用版本控制工具进行代码管理、学会写出高质量的代码等。 通过完成这个大作业,学生可以提高自己的编程能力和解决问题的能力,同时也培养了自己的学习能力和团队合作能力。同时,完成这个大作业也可以作为学生的工作经验和实践能力的体现,对于未来的学习和就业都具有积极的意义。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值