首页 > 编程语言 >笨办法学Python3 习题26 恭喜你,现在可以考试了!

笨办法学Python3 习题26 恭喜你,现在可以考试了!

时间:2023-10-08 23:35:30浏览次数:50  
标签:26 笨办法 dogs beans print world 习题 txt jars

下载代码learnpythonthehardway.org/python3/exercise26.txt

进行修改

 1 print("How old are you?", end=' ')
 2 age = input()
 3 print("How tall are you?", end=' ')
 4 height =input()                         # 没有input()
 5 print("How much do you weigh?", end=' ')# 没加括号
 6 weight = input()
 7 
 8 print(f"So, you're {age} old, {height} tall and {weight} heavy.")
 9 
10 from sys import argv                    # 没有导入模块
11 script, filename = argv
12 
13 txt = open(filename)                    # filename没拼写对
14 
15 print(f"Here's your file {filename}:")  # 没有加f
16 print(txt.read())                       # txt少t
17 
18 print("Type the filename again:")
19 file_again = input("> ")
20 
21 txt_again = open(file_again)
22 
23 print(txt_again.read())
24 
25 
26 print("Let's practice everything.")                      #里面有单引号,外面就用双引号
27 print("""You\'d need to know \'bout escapes 
28       with \\ that do \n newlines and \t tabs.""")       #没用三对引号
29 
30 poem = """
31 \tThe lovely world
32 with logic so firmly planted
33 cannot discern \n the needs of love
34 nor comprehend passion from intuition
35 and requires an explanation
36 \n\t\twhere there is none.
37 """
38 
39 print("--------------")                     # 特殊符号也要用引号
40 print(poem)
41 print("--------------")
42 
43 
44 five = 10 - 2 + 3 - 6
45 print(f"This should be five: {five}")       # 少半个括号
46 
47 def secret_formula(started):                # 函数没有加冒号
48     jelly_beans = started * 500
49     jars = jelly_beans / 1000
50     crates = jars / 100                     # 少写/ 运算符
51     return jelly_beans, jars, crates
52 
53 
54 start_point = 10000
55 beans, jars ,crates= secret_formula(start_point)  # 左边少写一个变量
56 
57 # remember that this is another way to format a string
58 print("With a starting point of: {}".format(start_point))
59 # it's just like with an f"" string
60 print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
61 
62 start_point = start_point / 10
63 
64 print("We can also do that this way:")
65 formula = secret_formula(start_point)
66 # this is an easy way to apply a list to a format string
67 print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
68 
69 
70 
71 people = 20
72 cats = 30
73 dogs = 15
74 
75 
76 if people < cats:
77     print ("Too many cats! The world is doomed!") # 没加括号
78 
79 if people > cats:                                 # < 改成 >
80     print("Not many cats! The world is saved!")
81 
82 if people < dogs:
83     print("The world is drooled on!")
84 
85 if people > dogs:                                 # 没加冒号
86     print("The world is dry!")
87 
88 
89 dogs += 5
90 
91 if people >= dogs:
92     print("People are greater than or equal to dogs.")
93 
94 if people <= dogs:                                  # 没加冒号
95     print("People are less than or equal to dogs.") # 没加引号
96 
97 
98 if people == dogs:                                  # 判断是否相等要用== 而不是= 这是赋值的意思
99     print("People are dogs.")
PS C:\Users\Administrator\lpthw> python ex26.py test20.txt
How old are you? 23
How tall are you? 164
How much do you weigh? 53
So, you're 23 old, 164 tall and 53 heavy.
Here's your file test20.txt:
This is line
This is line
This is line
Type the filename again:
> test20.txt
This is line
This is line
This is line
Let's practice everything.
You'd need to know 'bout escapes
      with \ that do
 newlines and    tabs.
--------------

        The lovely world
with logic so firmly planted
cannot discern
 the needs of love
nor comprehend passion from intuition
and requires an explanation

                where there is none.

--------------
This should be five: 5
With a starting point of: 10000
We'd have 5000000 beans, 5000.0 jars, and 50.0 crates.
We can also do that this way:
We'd have 500000.0 beans, 500.0 jars, and 5.0 crates.
Too many cats! The world is doomed!
The world is dry!
People are greater than or equal to dogs.
People are less than or equal to dogs.
People are dogs.
PS C:\Users\Administrator\lpthw>

 

标签:26,笨办法,dogs,beans,print,world,习题,txt,jars
From: https://www.cnblogs.com/luxiaoli/p/17750470.html

相关文章

  • 关于大顶堆和小顶堆习题的解决
    好吧,不得不承认的是,我之前对于堆的知识确实没理解,现在急用它,就急学!一般的习题的话,就是要求我们判断某个序列,是不是大顶堆或者小顶堆。小顶堆要求,k(i)≤k(2i)且k(i)≤k(2i+1)大顶堆要求,k(i)≥k(2i)且k(i)≥k(2i+1)就只需要这两个条件就能判断顶堆是否成立啦~~......
  • 建表,和练习题
    目录建库注意::整形和浮点型不用加''号,其他字符串型那部分需要加''表一联合主键001建表练习题查询练习sql练习建库createdatabaselinux注意::整形和浮点型不用加''号,其他字符串型那部分需要加''表一字段数据类型要求是否为空注释sno最多20位否学号(主键)sn......
  • 习题专题
    习题3:在有序的元组中查找元素方法一:利用遍历元组来查找#include<stdio.h>//遍历的方法查找元素intmain(){ intr=0;//为查找的数初始化 printf("请输入要查找的数字:");scanf("%d",&r);//输入要查找的数字 intnumber=r; inti=0; chararr1[]={1,2,3,4,5......
  • 习题专题
    习题4:演示多个字符从两端移动中间汇聚#include<stdio.h>#include<string.h>#include<windows.h>#include<stdlib.h>intmain(){ intsl=strlen("welcomebit!!!!!!");//strlen()遇到\0会停止!!! chararr1[]="welcomebit!!!!!!"; cha......
  • 【UVA 12657】Boxes in a Line 题解(静态双向链表)
    您在编号为1的表格上有n个方框。n从左到右。您的任务是模拟4命令类型:•1XY:将框X向左移动到Y(如果X已经是Y的左侧,则忽略此项)•2XY:将框X向右移动到Y(如果X已经是Y的右侧,则忽略此项)•3XY:交换盒X和Y•4:反转整条线路。命令保证有效,即X不等于Y。例如,如果n=6,在执行114之后,该行......
  • c语言代码练习(与“&”)26
    需求:求一个整数存储在内存中二进制中的1的数量#define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>intmain(){intnum=0;intinput=0;printf("请输入你想要统计的数字:");scanf("%d",&input);inti=0;for(i=0;i<32;i+......
  • oj练习题 数字 eval 整数 int ???
      s=input()if'helloworld!'==s.casefold():print("Yes")else:print("No")    A+B问题II描述亲爱的小朋友们,大家好!今天我们来探讨一下大家都会做的A+B的问题,给你两个数A和B,请你输出这两个数的和。输入输入两个数字,a和b输出输出一个......
  • SI3262—高度集成的低功耗SOC13.56MHz读卡器芯片 自带触摸
    Si3262是一款高度集成的低功耗SOC芯片,其集成了基于RISC-V核的低功耗MCU和工作在13.56MHz的非接触式读写器模块。MCU模块具有低功耗、LowPinCount、宽电压工作范围,集成了13/14/15/16位精度的ADC、LVD、UART、SPI、I2C、TIMER、WUP、IWDG、RTC、TSC等丰富的外设。内核采用RISC-V......
  • 笨办法学Python3 习题25 更多更多的训练
    练习内容:将ex25模块导入在终端中手动运行函数查看变化结果退出quit()1defbreak_words(stuff):2"用来分割参数元素"3words=stuff.split('')4returnwords56defsort_words(words):7"用来将参数元素升序排列"8returnsorted......
  • 2310-数组习题
     strlen函数-求字符串长度的,找\0之前出现的字符个数 sizeof-操作符-计算变量/类型所占内存大小,单位是字节答案为A  #include<stdio.h>voidinit(intarr[],intsz){for(inti=0;i<sz;i++)arr[i]=0;}voidprint(intarr[],intsz){......