Git Product home page Git Product logo

python-crash-course-homework's Introduction

《Python编程从入门到实践》课后练习

第一部分-基础知识

  • chapter02_变量和简单数据类型
  • chapter03_列表简介
  • chapter04_操作列表
  • chapter05_if语句
  • chapter06_字典
  • chapter07_用户输入和while循环
  • chapter08_函数
  • chapter09_类
  • chapter10_文件和异常
  • chapter11_测试代码

第二部分-项目

项目1:外星人入侵

  • chapter12_武装飞船
  • chapter13_外星人
  • chapter14_记分
    项目地址

项目2:数据可视化

  • chapter15_生成数据
  • chapter16_下载数据
  • chapter17_使用API

项目3:Web应用程序

  • chapter18_Diango入门
  • chapter19_用户账户
  • chapter20_设置应用程序的样式并对其进行部署
    项目地址

python-crash-course-homework's People

Contributors

alberthao avatar li-xw707 avatar mss12138 avatar octopuslian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-crash-course-homework's Issues

TypeError: cannot concatenate 'str' and 'Quitter' objects

运行7-4程序

prompt = "\nTell me Pizza Toppings"
prompt += "\nEnter 'quit' to end the program."

active = True
while active:
    message = input(prompt)

    if message == 'quit':
        active = False
    else:
        print("add " + message)

报错信息

$ python -u 7-4.py 

Tell me Pizza Toppings
Enter 'quit' to end the program.quit
Traceback (most recent call last):
  File "7-4.py", line 11, in <module>
    print("add " + message)
TypeError: cannot concatenate 'str' and 'Quitter' objects

我的理解

input交互进来的message,应该就是string类型啊。

NameError: name 'print_models' is not defined

运行8-16print_models.py程序

import printing_functions

unprinted_designs = ['iphone case', 'robot pendant', 'dodecahedron']
completed_models = []

print_models(unprinted_designs, completed_models)
show_completed_models(completed_models)

报错信息

Traceback (most recent call last):
  File "/home/zoctopus/code/github_organization/programming-book-practice/Python-Crash-Course-Homework/chapter08/print_models.py", line 6, in <module>
    print_models(unprinted_designs, completed_models)
NameError: name 'print_models' is not defined

思考

按照书上讲解,import文件名后,这个被引入文件里的所有定义的函数都是通用的。
为什么报not defined的错误呢?

IOError: [Errno 2] No such file or directory: 'learning_python.txt'

10-1练习

--- Reading in the entire file:
Traceback (most recent call last):
  File "./Python-Crash-Course-Homework/chapter10/10-1.py", line 7, in <module>
    with open(filename) as f:
IOError: [Errno 2] No such file or directory: 'learning_python.txt'

文件确实存在,文件名没有写错,路径正确,是哪里出了问题?

One problem

IN 9.8 Privileges类不是一个管理类的一个子类,所以在定义管理类的实例eric的时候eric.privilege.show.privilege是错误的因为eric的 privilege 没有对应的function

Homework:9-4_output puzzled

9-4.py Output

Number served: <bound method Restaurant.set_number_served of <__main__.Restaurant instance at 0x7fb4470ac998>>
Number served: 430
Number served: 1257
Number served: 1496

Why not first Number served is 0 ?

super() takes at least 1 argument (0 given)

练习 9-6,9-7,9-8时出现的错误

Traceback (most recent call last):
  File "./Python-Crash-Course-Homework/chapter09/9-8.py", line 44, in <module>
    eric = Admin('eric', 'matthes', 'e_matthes', '[email protected]', 'alaska')
  File "./Python-Crash-Course-Homework/chapter09/9-8.py", line 24, in __init__
    super().__init__(first_name, last_name, username, email, location)
TypeError: super() takes at least 1 argument (0 given)

NameError: name 'z' is not defined

运行7-10程序:

name_prompt = "\nWhat's your name? "
place_prompt = "If you could visit one place in the world, where would it be? "
continue_prompt = "\nWould you like to let someone else respond? (yes/no) "

responses = {}

while True:
    name = input(name_prompt)
    place = input(place_prompt)

    responses[name] = place

    repeat = input(continue_prompt)
    if repeat != 'yes':
        break

print("\n--- Results ---")
for name, place in responses.items():
    print(name.title() + " would like to visit " + place.title() + ".")

报错信息

$ python -u 7-10.py 

What's your name? z
Traceback (most recent call last):
  File "7-10.py", line 8, in <module>
    name = input(name_prompt)
  File "<string>", line 1, in <module>
NameError: name 'z' is not defined

10.3.4 else代码块:try-except代码块为什么可以放在if...else...之间?

请教:
在 if 和 else 之间编写任何其他代码,会出现SyntaxError,
为什么该小节例子中 if和else之间的代码却可以正常运行呢?

print("Give me two numbers, and I'll divide them.")
print("Enter 'q' to quit.")

while True:
    first_number = input("\nFirst number: ")
    if first_number == 'q':
        break
    second_number = input("Second number: ")
    try: 
        answer = int(first_number) / int(second_number)
    except ZeroDivisionError: 
        print("You can't divide by 0!")
    else: 
        print(answer)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.