CM 3.2 variables MrG 2011.1017

3699 days ago by calcpage123

x=5 type(x) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < type 'int' > }
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < type 'int' > }
y=2.3 type(y) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < type 'float' > }
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < type 'float' > }
z='baldwin' type(z) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < type 'str' > }
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < type 'str' > }
taxRate=0.05 price=48 total=price*(1+taxRate) total 
       
\newcommand{\Bold}[1]{\mathbf{#1}}50.4
\newcommand{\Bold}[1]{\mathbf{#1}}50.4
print('Total sale: {0:6.2f}'.format(total)) 
       
Total sale:  50.40
Total sale:  50.40
a=['al','betty'] b=a b 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\hbox{al}, \hbox{betty}\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\hbox{al}, \hbox{betty}\right]
a.append(4) b 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\hbox{al}, \hbox{betty}, 4\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\hbox{al}, \hbox{betty}, 4\right]
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\hbox{al}, \hbox{betty}, 4\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\hbox{al}, \hbox{betty}, 4\right]
#1) r=5 a=pi*r**2 a.n() 
       
\newcommand{\Bold}[1]{\mathbf{#1}}78.5398163397448
\newcommand{\Bold}[1]{\mathbf{#1}}78.5398163397448
pi.n() 
       
\newcommand{\Bold}[1]{\mathbf{#1}}3.14159265358979
\newcommand{\Bold}[1]{\mathbf{#1}}3.14159265358979
#2) x=5 x=2*x x 
       
\newcommand{\Bold}[1]{\mathbf{#1}}10
\newcommand{\Bold}[1]{\mathbf{#1}}10
#3) name, d7, first_name, lastName, Amt 
       
#4) firstName="bob" lastName="ross" wholeName=first + " " + last wholeName 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'first' is not defined
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_16.py", line 10, in <module>
    exec compile(u'print _support_.syseval(python, u\'#4)\\nfirstName="bob"\\nlastName="ross"\\nwholeName=first + " " + last\\nwholeName\', __SAGE_TMP_DIR__)
  File "", line 1, in <module>
    
  File "/home/medlock/sage-4.7.1/devel/sagenb/sagenb/misc/support.py", line 481, in syseval
    return system.eval(cmd, sage_globals, locals = sage_globals)
  File "/home/medlock/sage-4.7.1/local/lib/python2.6/site-packages/sage/misc/python.py", line 53, in eval
    eval(compile(s, '', 'exec'), globals, globals)
  File "", line 4, in <module>
    
NameError: name 'first' is not defined
#5) a=3 b=2 a=a+b b=a-b print(a) print(b) 
       
5
3
5
3
#6) age=5 print(age) print(len(age)) 
       
5
Traceback (click to the left of this block for traceback)
...
TypeError: object of type 'int' has no len()
5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_18.py", line 10, in <module>
    exec compile(u"print _support_.syseval(python, u'#6)\\nage=5\\nprint(age)\\nprint(len(age))', __SAGE_TMP_DIR__)" + '\n', '', 'single')
  File "", line 1, in <module>
    
  File "/home/medlock/sage-4.7.1/devel/sagenb/sagenb/misc/support.py", line 481, in syseval
    return system.eval(cmd, sage_globals, locals = sage_globals)
  File "/home/medlock/sage-4.7.1/local/lib/python2.6/site-packages/sage/misc/python.py", line 56, in eval
    eval(z, globals)
  File "", line 1, in <module>
    
TypeError: object of type 'int' has no len()
age="five" print(age) print(len(age)) 
       
five
4
five
4
#7) x=7 x=x*x x=x*x x 
       
\newcommand{\Bold}[1]{\mathbf{#1}}2401
\newcommand{\Bold}[1]{\mathbf{#1}}2401
#8) n=5 s="+"*n s 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{+++++}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{+++++}
"len = " + str(len(s)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{len = 5}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{len = 5}