Motive Paiza has recently released Code Chronicle, which combines RPG games and code learning.
So I tried to solve the problem, but since it is for beginners, the question about the basic syntax was repeatedly asked, so the difficulty level is not difficult, but the following questions were asked. (Not exactly the same.)
#Please output the variable type of pi
pi = 3.14
print("") #int, str,Please enter one of the floats.
The answer is print ("float")
, but I wondered if it could be used because there is a type
function. : rolling_eyes:
Method
If you simply use the type
function, ...
>> type(pi)
#<class 'float'>
The type of the class is output as shown.
I thought I should simply use str ()
, but ...
>> str(type(pi))
#"<class 'float'>"
The " <class'float'> "
is output as a string, which is different from the expected float
.
Read about type functions in Python document Looking at it,
The * name string is the class name and has the __name__
attribute. *
Since it was written, you can get float
by getting the attribute of the class.
>> type(pi).__name__
# `float`
Digest
If you get the problem of #Please output variable type
, you can use any of integer, string, and decimal point types.
type(pi).__name__
It is a silver bullet that will be the correct answer if you write. : gun:
Future Code Chronicle I think it's an app game that matches the program learning that the government is pushing forward from next year: robot :. If you create a problem while considering the game balance and design a mechanism to create a problem, it seems that operation will be difficult unless you have all the development members. This difficulty may be fine for beginners.
Reference -Code Chord -type function
Recommended Posts