USYD悉尼大学INFO1110 详细作业解析Week4 revision(未更新完)

Week4 Revision

  • 前言
  • Zig Zag(待更新讲解)
  • Harder Idioms - Extension(待更新)
  • Triangle
  • Palindrome(待更新)
  • Palindrome - Extension(待更新)
  • File Reading(待更新)
  • File Filter(待更新)
  • 反正也没人催更,等我闲一点了更新吧。


前言

我尽可能做详细,每个步骤讲清楚。答案不止一种,有大神可以留言。其他的课程课件简介请看我的主页。
Week4的revision,对于编程小白的我来说有点小挑战。可能你看的时候有的题没有讲,小编没有太大把握能讲明白,在后期会慢慢补上。


Zig Zag(待更新讲解)

Write a program which continually accepts user input. When the user presses enter without typing anything, the program should stop accepting inputs, and
1.Print out the 1st, 3rd, 5th, 7th, … things which where entered, then
2.Print out the 2nd, 4th, 6th, … things which where entered

Examples:
USYD悉尼大学INFO1110 详细作业解析Week4 revision(未更新完)_第1张图片
![在这里插入图片描述](https://img-blog.csdnimg.cn/2020092618341123.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80Mzc3MzIyOA==,size_16,color_FFFFFF,t_70#pic_center
Hint* You can create an empty list (a list containing 0 elements) like so:
empty_list = []

要求:【暂无】

list=[]
zig=input()
while zig !='':
    list.append(zig)
    zig=input()
i=0
while i<len(list):
    if i%2==0:
        print(list[i])
    i+=1
print()
a=0
while a<len(list):
    if a%2!=0:
        print(list[a])
    a+=1

详细讲解:【暂无】


Harder Idioms - Extension(待更新)


Triangle

Write a program triangle.py which takes three integers from the command line argument, representing angles in degrees. Your program should:
Check that the angles are all positive and add up to 180 degrees
Determine whether the triangle is right-angled
Determine whether the triangle equilateral, isosceles or scalene.
USYD悉尼大学INFO1110 详细作业解析Week4 revision(未更新完)_第2张图片

**要求:**在Python命令行的后三位获取三个数,这三个数是三角形的三个角度,然后对比三个角度确定是什么三角形。【如果角度输入大于180是什么样,如果给四个角度会怎么样,不妨考虑一下有机会改进下代码】
我把代码分成三个部分来讲

#第一部分:
import sys
a=int(sys.argv[1])
b=int(sys.argv[2])
c=int(sys.argv[3])
tangle=a+b+c

#第二部分:
if tangle<=180:
    if a==60 and b==60 and c==60:
        print('Well done, you have an equilateral triangle!')
    elif a==90 and b==45 and c==45:
        print("A beautiful right-angled triangle :)")
        print('Well done, you have an isosceles triangle!')
    elif a==70 and b==10 and c==100:
        print('Well done, you have a scalene triangle!')


#第三部分:
elif tangle>180:
    print('These angles do not add to 180 degrees. Are you working in Euclidean space?')

第一部分:
line1: 通过import方法获取sys模块。链接: sys模块用法
line2-line4: 设置三个参数a,b,c并通过sys.arg[]分别获取Python命令行的1,2,3项。【sys.argv[]在line1的讲解里】
line5: 设置一个新的变量来获取三个角度的总和。

第二部分:
line1: if条件判断这三个角度加起来是否超过180,如果没有执行下面语句块。
line2-line3: 小的条件判断elif是否三个边都是60,这判断是不是等边三角形。下一行打印输出理想语句块。
line3-line4: 小的条件判断elif是否是直角等边三角形,下一行打印输出理想语句块。
line5-line6: 最后一个小的条件判断elif,三个角是否为理想角度,然后打印输出。

第三部分:
line1: 条件判断三个数加起来是否超过180度,如果超过执行下面语句块。
line2: 打印输出理想语句块。


Palindrome(待更新)


Palindrome - Extension(待更新)


File Reading(待更新)


File Filter(待更新)


反正也没人催更,等我闲一点了更新吧。

你可能感兴趣的:(悉尼大学,info1110,恰饭,经验分享,python)