首页 > 编程语言 >COMM 337 Python code in your notebook

COMM 337 Python code in your notebook

时间:2024-10-01 10:45:36浏览次数:9  
标签:code last Python 337 assign XX file variable your

COMM 337: Homework 2

DUE DATE: Oct 2, 2024 12:00pm

This is HW2 Python assignment. There are 13 problems. Each problem is7 points and the total is 100 points (9 for following file/print format).Instructions:

  1. Late submissions will not be accepted.
  2. Submit your Python code in UBC Canvas. DO NOT email your homework toTA or me.
  1. Don’t submit the output txt file. I will run your Python code to generate it.(Initial Setup) Create and download:
  1. Create a new python notebook for this homework and download the“last.txt” file into the same directory, where your notebook is located.

Write your Python code in your notebook file for Problems 2 to 20.

  1. Open “last.txt” file with “read-only” file mode.
  2. Find the number of characters in the file and assign it to “ans3”variable.
  1. Find the number of words (including both numbers and names) in thefile and assign it to “ans4” variable.
  1. Find the number of lines in the file and assign it to “ans5” variable.
  2. Count the last names starting with “L” and assign it to “ans6” variable.
  3. Count the last names ending with “E” and assign it to “ans7” variable.
  4. Count the last names with length 3 and assign it to “ans8” variable.
  5. Count the numbers larger than 0.1 and assign it to “ans9” variable.
  6. Count the numbers smaller than 0.02 and assign it “ans10”variable.
  1. Get the number next to your last name and assign it to “ans11”variable. If your last name doesn’t appear, “ans11” should be 0.
  1. Find the last name that comes last in the dictionary order andassign it to “ans12” variable.
  1. Find the last name that comes first in the dictionary order andassign it to “ans13” variable.
  1. Find the longest last name and assign it to “ans14” variable.
  1. Find the shortest last name and assign it to “ans15” variable.(Note: don’t worry about the weird last name in the last.txt file. I put itthere intentionally.)
  1. Create a new file “hw2_answers_STUDENTID_FIRST代 写COMM 337 Python code in your notebook  _LAST.txt” usingopen() function with “write” mode, where FIRST and LAST should beyour first and last names. For example,hw2_answers_1234_JANE_DOE.txt will be my output file.
  1. Write your student id, first name, last name, and email address inthe first line of “hw2_answers_STUDENTID_FIRST_LAST.txt” file.
  1. Write all your answers into the“hw2_answers_STUDENTID_FIRST_LAST.txt” file. Each answer will takea line with “answerXX=YY” format. Use your ansXX variables. Don’t dohard coding by using the actual values.
  1. Write “Homework 2 is done!!!” in the last line of“hw2_answers_STUDENTID_FIRST_LAST.txt” file.
  1. Close “ hw2_answer_STUDENTID_FIRST_LAST.txt” file using close()method.

Submission:

Export your file as a .py file and submit it to Canvas. Please DO NOT submit your .ipynb file. Also, make sure you EXPORT the filefrom jupyter and not just rename the file extension. You do NOT needto submit your generated output text file.Your output text file should look like this:1234 Jane Doe [email protected]

answer3=XX

answer4=XX

answer5=XX

answer6=XX

answer7=XX

answer8=XX

answer9=XX

answer10=XX

answer11=XX

answer12=XX

answer13=XX

answer14=XX

answer15=XX

Homework 2 is done!!!

标签:code,last,Python,337,assign,XX,file,variable,your
From: https://www.cnblogs.com/comp9021/p/18442738

相关文章

  • [python] 基于PyOD库实现数据异常检测
    PyOD是一个全面且易于使用的Python库,专门用于检测多变量数据中的异常点或离群点。异常点是指那些与大多数数据点显著不同的数据,它们可能表示错误、噪声或潜在的有趣现象。无论是处理小规模项目还是大型数据集,PyOD提供了50多种算法以满足用户的需求。PyOD的特点包括:统一且用户友......
  • 力扣(leetcode)每日一题 1845 座位预约管理系统| treeSet和priority Queue的区别|线段树
    之前发过一篇,感觉还有深挖的地方,于是又补充一些信息这题目虽然是middle难度题目,要解答出来是只要easy的时间,但是深挖可以有hard的难度题解1可以帮助复习线段树的使用,题解2可以复习一下java基础知识题解1线段树这是自己憋出来的线段树classSeatManager{......
  • Python 进程:掌控并发世界的钥匙
    引言进程,作为一种操作系统的基本调度单元,它不仅能够独立执行程序,还支持并发操作,这对于提升程序效率、改善用户体验至关重要。特别是在Python这样的解释型语言中,由于全局解释器锁(GIL)的存在,使得多线程在CPU密集型任务上的表现不如预期。此时,利用多进程便成为了一种有效的解决策略。......
  • Python 并发新境界:探索 `multiprocessing` 模块的无限可能
    引言随着硬件技术的发展,多核处理器已经成为标准配置。这意味着我们的计算机拥有执行多个任务的能力。然而,默认情况下,Python程序由于全局解释器锁(GIL)的存在,并不能充分利用这些核心资源。这就引出了multiprocessing模块的重要性——它通过创建独立进程来绕过GIL限制,从而实现真正的并......
  • 教你如何免费获取股票数据用python、JavaScript (Node.js)、JAVA等多种语言的实例代码
    ​近一两年来,股票量化分析逐渐受到广泛关注。而作为这一领域的初学者,首先需要面对的挑战就是如何获取全面且准确的股票数据。因为无论是实时交易数据、历史交易记录、财务数据还是基本面信息,这些数据都是我们进行量化分析时不可或缺的宝贵资源。我们的核心任务是从这些数据......
  • Python工程数学2程序开胃菜(上)
    2数学程序开胃菜在上一章中(https://mp.weixin.qq.com/s/kKenXcEXIeLd_u_2kymF8A),我们介绍了python的IDE;用numpy实现向量计算;用Matplotlib绘图;用sympy实现微积分和求导;用SciPy实现积分;用VPython实现弹跳球动画。在本章中,您将了解Python命令式编程风格的线性程序结构以及分......
  • python tkinter 开发测试
    fromtkinterimport*defname_1_cs():ydm_1_2.place_forget()ydmwz_1_2.place_forget()ydmwz_1_2_B1.place_forget()xz_1_1.place_forget()ydmwz_1_2_B2.place_forget()xz_1_2.place_forget()mulu_1.place_forget()mulu_2.plac......
  • VScode Cmake-tools 部分问题记录
    我的VisualStudioCode先前一直安装了cpp-tools和cmake-tools。随后,我升级了我的GCC环境版本。然而,重新启动VisualStudioCode后,旧的GCC版本仍保留在工具包中。起初,我以为是cpp-tools插件的问题,一直无法解决这个bug。后来卸载了相关插件后才发现是cmake-tools的......
  • 【LeetCode Hot 100】23. 合并K个升序链表
    题目描述看到这个题目会想起之前做过的合并2个升序链表。在那个题目中,由于两个链表都已经是升序的,可以将两个链表的元素进行逐个比较并添加到答案链表中。但是在本题中,每次循环都需要在k个链表的当前元素中找出最小的,而且需要在所有k个链表都遍历完之后跳出循环,所以效率比较低。......
  • Python函数进阶:让你的代码更优雅的秘密武器
    引言你是否曾在编写Python代码时感到困惑,尤其是在处理函数时?你并不孤单!根据一项调查,超过70%的开发者在学习Python时都曾遇到过函数的各种难题。想象一下,如果你能掌握一些高级用法,像装饰器、匿名函数、可变参数和关键字参数等,你的代码将会变得多么优雅和高效!在这篇文章中,我们将......