Python Learning: Fundamentals (5) conversion of arbitrary **m into n-ary * * __python

Source: Internet
Author: User
[0] The built-in functions can be consulted by Help or https://docs.python.org/3/library/. [1] for the conversion of the binary, the 10 binary integer to 2,8,16,bin (), Oct (), Hex () can be converted to the corresponding system. [2] The conversion of each system into 10, int (obxxxxx), int (ox ...) or int (' xxxxxxxxxx ', 2), int (' xxxxxxxx ', 8) The following code is used as an exercise to solve any conversion of M-feed to n -ary. As a good habit, we should check all possible inputs, m,n must be integers, the number to be processed should also be integers (but not necessarily positive numbers), m if not number, calling int would be wrong, How can I tell if a string is a number? You need to use regular expressions here and then process them later.
m = Int (input (' please input the orginal number system ')) n = Int (input (' please input the Objectiv E number system ') M_str = input (' The orginal Integer ') if (float (m_str) ==int (float (m_str)): m_number = Int (m_st
                R,M) #get The numeric value of M symbol = ' if (m_number<0): #figure out the final symbol
                M_number = ABS (M_number) #get positive value symbol = '-' if (n = =): # m convert to 10 Print (Symbol+str (m_number)) Else: #10 convert to n ans = "while (M_number) : ans = str (m_number%n) + ans#doing the MoD m_number = m_number//n#warning !!: Using//Not/print (Symbol+ans) #print the answer else:print (' Input is not integer ') 

====================================================================================== Society defines functions: def:, return value ( Multiple return values are actually a tuple), parameter checking. The code for solving the solution of a two-time equation.

Import Math
def quadratic (A, B, c):
    if (not Isinstance (A, (int,float)) and isinstance (b, (int,float)) and Isinstance (c, (Int,float))): #check The argument type
        print (' The a,b,c is Typerror ') return
    if (b*b>=4* A*C):
        r = math.sqrt (b*b-4*a*c) return
        (-b+r)/(2*a), (-b-r)/(2*a)
    else:
        print (' There isn't real root ')
        return

print (quadratic (2, 3, 1)) print (
quadratic (1, 3,-4))
print (quadratic (1,-2, 1
)) Print (Quadratic (5, 1, 3))
print (Quadratic (' 1 ', 3,-4))

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.