代写Project #2 – Big Practice帮做Python编程


Project #2 – Big Practice

Making many files to solve many different problems

Your Task

Your task is to solve all the provided problems using the python skills we've learned so far. 

There are 6 problems to solve. Each one should be done in their own .py file, and they must be named exactly what is asked for. Note the points for each problem

All problems should be no more than a couple of lines. Occasionally you will be asked to include certain lines at the start of the file. 

You will be penalized if the statements in the program do not work in the same general way as the problem describes, even if the program works correctly otherwise. 

After the project is due, your program will also be graded by hand. The autograder is not necessarily the final grade you will receive on the project.

You must include a comment at the top of all your program files containing your name, “Project #2”, and the date you turn it in.

 Problems

1. A starting example repeat.py  (20 point)

The first program is provided to you as a starting example. It’s already implemented. All you need to do is to download the file, open it in VSCode, add your name/date. You do NOT need to change the program code. This example reads in a user input, stores it in a variable, and prints it back to the terminal. After you have edited the comments, save it. You can then run it, try some different inputs, and verify the outputs are correct.

File download: repeat.py      (click download button at the top by the printer icon)

This first problem should now serve as your template for the rest of the problems

2. Implement temp.py (20 points)

Create a new program, name it temp.py

This program will first ask the user to enter a floating point number representing a temperature in Fahrenheit. It should then convert the input number to Celsius and Kelvin respectively, and print them out on separate lines. The formulas for temperature conversions are:

C = (F - 32) * 5 / 9

K = C + 273.15

Where F is Fahrenheit, C is Celsius and K is Kelvin.

Running a correct implementation of this program could look like:

Enter temperature in Fahrenheit: 31.41

31.41 degrees Fahrenheit is equivalent to:

-0.3277777777777777 degrees Celsius

272.8222222222222 Kelvin

Formatting details:

● The last number on the second-to-last line must be the Celsius value

● The last number on the last line must be the Kelvin value

● No other lines of text or additional formatting is necessary. Do NOT print extra lines.

Do not worry about the number of decimal places, just include all you get from the conversion process (ie don't round or cast the result)

3. Implement cube.py (20 points)

Create a new program, name it cube.py

This program will first ask the user to enter an integer representing the side length of a cube. It should then compute the volume and surface area of the cube, and print them out on separate lines.

For a given side length:

The volume is the side length cubed

The surface area is 6 times the side length squared (as a cube has 6 sides)

Running a correct implementation of this program could look like:

Enter the length of the cube: 5

A cube with length 5 has:

Volume of 125

Surface area of 150

Formatting details:

● The last number on the second-to-last line must be the volume as an integer number.

● The last number on the last line must be the surface area as an integer number.

● No other lines of text or additional formatting is necessary

4. Implement add_or_find.py (15 points)

Download this file: add_or_find.py

After the creation of the list names on line 2, your program should:

● Ask the user what they want to add to the list

● If the item is already in the list, print the index where it is found

● If the item isn't in the list, add it to the end, and print out the list.

Running a correct implementation of this program could look like:

Add a name? whalers

['blues', 'canucks', 'ducks', 'jets', 'kings', 'kraken', 'panthers', 'penguins', 'rangers', 'wild','bulls', 'cavaliers', 'celtics', 'kings', 'knicks', 'lakers', 'raptors', 'rockets', 'suns', 'warriors', 'whalers']

Add a name? ducks

Already in the list, index: 2

The prints described above must be the last thing your program prints out before it ends. Do not print anything else after it or it will fail the autograder.

HINTS:

● To test if a value is in a list, you can use the membership operator (in) (link)

● To find the index of a value you know to be in a list, you can use the index() method (link)

● I made this one sports themed, for all you sports-heads

5. Implement triangle_id.py (10 points)

Create a new program, name it triangle_id.py

This program will first ask the user to enter three different integers. We will call them a, b and c. Each represents the length of a side of a triangle (a and b are the legs, c is the hypotenuse). Your program should print out invalid, equilateral, isosceles, or scalene depending on the values of a,b,c.

A triangle is invalid if the length a+b is less than or equal to the length of c. A triangle is equilateral if a, b, and c are all the same length. A triangle is isosceles if two of a, b, and c are equal (for example if a=b but != c). If a triangle isn't any of the previous types, we will say it's scalene.

YOU DO NOT NEED TO UNDERSTAND THE UNDERLYING MATH TO SOLVE THIS PROBLEM. You just need to know how to take the above rules and turn them into code.

This is a simple control flow diagram describing the solution to the problem. Use the tools we talk about in class to convert this diagram into code. Remember triangles represent branches, the code should start at start, and only be able to follow along the arrows.:

Running a correct implementation of this program could look like:

Enter a: 5

Enter b: 5

Enter c: 5

equilateral

Enter a: 5

Enter b: 5

Enter c: 9

isosceles

Enter a: 5

Enter b: 5

Enter c: 12

invalid

The type of triangle must be in the last line your program prints out.

HINTS:

● To find if a triangle is equilateral, you need to do three different Boolean expressions. Those Boolean expressions need to be combined in some way, it will be worth your time to review the reading on logical operations (also this link: here)

● To find if a triangle is isosceles, you need to do three different Boolean expressions. The expressions themselves will look like your solution to finding equilateral triangles, but you will combine them differently. Review the same materials as above, but pick a different way to combine them.

6. Implement even_division.py (10 points)

Create a new program, name it even_division.py

Division is made up of two parts, the dividend and the divisor. The number that is being divided is the dividend, the number which we divide by is the divisor.

This program will first ask the user to enter the dividend, and then ask them to enter the divisor. Both will be integers and the user will never enter anything invalid (like giving 0 as the divisor).

The program should then check to see if the dividend is divisible by the divisor. A number is divisible by another if the division results in no decimal values. For instance, 12 is divisible by 3 (the result is 4) but it is not divisible by 5 (the result is 2.4)

*The program should output "True, {dividend} is divisible by {divisor}" or "False, {dividend} is not divisible by {divisor}" depending on the circumstance. Note, the print out should put the numbers in place of {dividend} and {divisor}. So for 12 and 3 this should be printed out "True, 12 is divisible by 3"

Running a correct implementation of this program could look like:

Enter dividend: 12

Enter divisor: 5

False, 12 is not divisible by 5

The formatting of this line needs to match the described* exactly, and it needs to be the last thing your program prints out

7. Implement anagram.py (5 points)

Create a program, name it anagram.py

A string is said to be an anagram of another string if it can be created by rearranging the letters of the other string. For example, fried is an anagram of fired and vice versa. Another example is listen and silent.

Your program should accept two strings, and should print out True if they are anagrams. It should print out False otherwise. YOU CANNOT USE LOOPS TO SOLVE THIS PROBLEM.

Running a correct implementation of this program could look like:

Enter first: santa

Enter second: stana

True

HINTS:

● You do not need loops, or branching to solve this problem. In fact, using them could make the problem much harder than it would be otherwise.

● Strings are hard to use, is there a way to turn them into a list of characters?

● Lists have many built-in methods that could be useful. What do all anagrams have in common? Could you reorder both lists to make identifying anagrams easier?

● Often solving CS problems is like solving a problem. You have to think about anagrams in a new way in order to teach them to a computer.

● BTW lists have a built in sort method, I wonder how that could be useful here???(https://www.w3schools.com/python/ref_list_sort.asp)

Testing

Test your programs completely. Run it several times: verify that for each section outputs the desired values, and that the prints match exactly to the desired. Once you have confirmed to yourself your program is functioning, you should submit it to the appropriate place on gradescope.com. If you fail any tests, gradescope will tell you which test, a small amount about the test, but it is up to you to figure out what went wrong. This is a very important part of the programming process.

Extra Credit

The extra credit are three additional problems you can attempt. These problems are meant to really test your understanding up to this point.

Extra Credit #1

Create a new program, name it perfect_weave.py

This program requests 3 inputs in order:

● A string, referred to as A here

● Another string, referred to as B here

● An integer, referred to as n here

It will then print out n copies of A with n copies of B interweaved / interleaved. So the output should look like ABABAB… in other words: A followed by B, repeated n times.

Running a correct implementation of this program could look like:

Enter first string: on

Enter second string: i

Enter a number: 2

onioni

Enter first string: flip

Enter second string: flop

Enter a number: 4

flipflopflipflopflipflopflipflop

Hints: Try to do a few examples by hand first, looking for a pattern in how the output relates to the input. The solution to this problem is deceptively simple, remember that we have already learned about an operator that lets us repeat strings!

Extra Credit #2

Create a new program, name it fraction_division.py

Division is made up of two parts, the dividend and the divisor. The number that is being divided is the dividend, the number which we divide by is the divisor.

The goal of this program is to show integer division results with fractions. The user inputs the dividend first, and then the divisor. You can assume both are positive integers. Your program should then print out a string showing the integer result of the division, including the quotient and remainder. Follow examples below for more insight.

Hint: the arithmetic operations you need to solve this problem already exist in Python.

This is also meant to test your knowledge of strings to get a perfect recreation of the formatting shown below. Note that after the equals: there is a newline and a tab.
Note: unlike the previous questions, for this question the formatting must exactly match the examples given below.

What is the dividend: 7

What is the divisor: 2

7/2 equals:

       3 and 1/2

What is the dividend: 50

What is the divisor: 10

50/10 equals:

       5 and 0/10

What is the dividend: 147

What is the divisor: 6

147/6 equals:

       24 and 3/6

Extra Credit #3

Create a new program, name it seconds.py, and implement it to complete the following task:

1. ask the user to enter a positive integer representing the number of seconds.

2. convert that to a total number of days, hours, minutes, and seconds such that hours must be between 0 and 23, minutes between 0 and 59, and seconds between 0 and 59. For example: 3599 seconds converts to 0 days, 0 hours, 59 minutes and 59 seconds;
90061 seconds converts to 1 day, 1 hour, 1 minute, and 1 second. 

3. output the result in 5 lines: the first line is the original number the user entered, followed by a space character, and the text seconds is equal to: then lines 2 to 5 are the number of days, hours, minutes, and seconds that you calculated.

Hint: for this program you will need to use the floor division operator // and the modulo % operator. First think about how to solve this problem by hand; next, write down code to implement your solution. Then test your program by running it with a few example inputs like those listed above.

Running a correct implementation of this program may look like:

Enter a number of seconds: 314159

314159 seconds is equal to:

3 days,

15 hours,

15 minutes, and

59 seconds.

Submission

When you are done, turn in the assignment via Gradescope, you should submit only your .py file. Make sure that your file names match exactly. 

After you submit, gradescope will automatically test your program, and you should shortly see the results from the tests. If you have failed any, a small amount of feedback might be given, and you will be allowed to resubmit your code. It is up to you to figure out what went wrong. This is a very important part of the programming process. We may offer assistance in finding the bug, but we will not bug fix for you.

After the project is due, your program will also be graded by hand. The autograder is not necessarily the final grade you will receive on the project.

Grading

After the due date, your project will also be hand graded. We are looking to see if your project was completed authentically, and if there are parts of your code that are partially correct and deserve partial credit.

In the report of your grade, you will see a score and a set of letter codes explaining what you did wrong. If you get 10 points, there will be no associated letter codes.

The grading codes A-E are defined and will be the same for all programs that you turn in. A summary of those codes is as follows:

A:   -10 (once) Student’s name is missing from the top of the program.

B:   -100 a Program cannot run due to syntax errors.

C:   -100 a Program crashes before finishing.

D:   -10 (once) Program uses overly advanced methods not yet discussed in class

E:   -25 (once) Program works correctly, but changes the assignment in order to do it.

In addition, penalties for this assignment only will be incurred for the following infractions (which may supersede some of the generic codes listed above):

F:  -10 (each) Required line of code is omitted (like omitting a Print statement, for example, either in part or in its entirety).

G: -15 (once) Project file is not named correctly, causing autograder to fail.

Each of the three extra credit items are worth +3.33 points added to the score only if implemented correctly. Incorrect implementation will not be penalized.

 


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图