Python exercises 2

Source: Internet
Author: User

If you really want to learn, learn what is not studious, if really want to learn the acme of Python, almost what they want to do, it is necessary to make perseverance, persist.

Then continue to update the Python Exercise 2, by updating the previous exercises to learn a lot of things

1. take any amount less than US $1, and then calculate what kinds of coins can be exchanged, how many are there? Coins have 1 cents, 5 cents, 10 cents, 25 cents 4 kinds, such as 0.76 dollars for 3 25 cents, 1 pieces 1 cents

1 #Encoding=utf-82 __author__='Heng'3  fromCopyImportDeepcopy#when you want to change the dictionary, remember to deep copy, otherwise the original dictionary will be affected4Money = Float (raw_input ("Please enter the money (dollar):"))5money = Int (100*Money )6Moneydic = {25:0,10:0,5:0,1: 0}7  forKeyinchMoneydic:8     ifMoney >=Key:9Moneydic[key] = Int (money/key)Tenmoney = Int (money%key) OneMoneydic1 = Deepcopy (moneydic)#This is a deep copy . A  forKeyinchMoneydic: -     ifMoneydic[key] = =0: -         delMoneydic1[key]#because of deep replication, the iterative object changes are not reported when a for loop iteration is made the  -  forKeyinchMoneydic1: -     Print("%s The%s cent"% (Moneydic1[key],key)),

Python exercises 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.