Python Programming Quick Start 3rd Chapter Practical Project Reference Answer

Source: Internet
Author: User

1#!/usr/bin/env python2#Coding:utf-83#Write by Mfyang4#collatz.py5#reads a value from the user and determines whether the value is an integer of type int, if not given an exception hint6#If this value is even then let this number//27#If this value is odd then let this number x3 + 18#by constantly invoking the return value of the function and printing the return value until the return value is 19 num = raw_input ("Please input a number:") 11#except Nameerror:12#print "Your input not a number"13 14defCollatz (num):15ifNum% 2 = =0:16returnNum//2 17Else: 18returnnum * 3 + 1 19returnNumIsnumber = 1 22Try: num =int (num)24exceptValueError:25Print "Your input not a nubmer"Isnumber =027 whileNum! = 1: 28ifIsnumber = = 1: num =Collatz (num)30PrintNum31Else: 32 Break

Python Programming Quick Start 3rd Chapter Practical Project Reference Answer

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.