1.19.2013 #Practical Programming #2

本文提供了一系列编程练习题目及其解答思路,涵盖了字符串操作、输入输出、条件判断等基本编程概念。通过这些练习,初学者可以更好地掌握编程语言的基础用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# Practical Programming
# Exercises - 3.8

# 1 - expressions
# ------------------------------------------------------------------------------

#print "'Comp''Sci'\t", 'Comp''Sci'
#print "'Computer' + 'Science'\t", 'Computer' + 'Science'
#print "'H20' * 3\t", 'H20' * 3
#print "'C02' * 0\t", 'C02' * 0, "\t(This is '' actually.)"

# 2 - phrases
# ------------------------------------------------------------------------------

#print 'a).', "They'll hibernate during the winter."
#print 'b).', '"Absolutely not," he said.'
#print 'c).', '"He said, \'Absolutely not,"\' recalled Mel'
#print 'd).', 'hydrogen sulfide'
#print 'e).', 'left\\right'

# 3 - rewrite
# ------------------------------------------------------------------------------

#print '\'\'\'A\nB\nC\'\'\''

# 4 - len()
# ------------------------------------------------------------------------------

#print len('')

# 5 - some prints
# ------------------------------------------------------------------------------

#x = 3
#y = 12.5
#print 'The rabbit is %d.' % x
#print 'The rabbit is', x, 'years old.'
#print y, 'is average.'
#print y, '*', x
#print y, '*', x, 'is %.1f.' % (y * x)

# 6 - True or False
# ------------------------------------------------------------------------------

#print '\'g\' == "g"',
#if 'g' == "g":
    #print '\tTrue'
#else:
    #print '\tFalse'

#print "'g' == 'G'",
#if 'g' == 'G':
    #print '\tTrue'
#else:
    #print '\tFalse'

#print "'a' >= 'b'",
#if 'a' >= 'b':
    #print '\tTrue'
#else:
    #print '\tFalse'

#print "'ant' < 'abc'",
#if 'ant' < 'abc':
    #print '\tTrue'
#else:
    #print '\tFalse'

#print "'ant' > 'Ant'",
#if 'ant' > 'Ant':
    #print '\tTrue'
#else:
    #print '\tFalse'

#print "'ant' > 'Abc'",
#if 'ant' > 'Abc':
    #print '\tTrue'
#else:
    #print '\tFalse'

#print "'ant' < 'anti'",
#if 'ant' < 'anti':
    #print '\tTrue'
#else:
    #print '\tFalse'

# 7 - raw_input()
# ------------------------------------------------------------------------------

#num = float(raw_input('enter a number: '))
#print 'The number you entered has been convert to float:', num

# 8 - An interesting question
# ------------------------------------------------------------------------------

#print '-' * 20
#print ">>>'abc' 'def'\n", 'abc' 'def'
#print '-' * 20
#print ">>> left = 'abc'\n", ">>> right = 'def'\n", ">>> left right\n", 'File "<stdin>" , line 1\n', 'left right\n', ' ^\n', 'SyntaxError: invalid syntax'
#print '-' * 20
#print "I think the reason why this happens is that when you enter the original\n", "string such as 'abc' or 'def', it's recognized as string as it is. But \n", "when you assign it to the variable such as left or right, it's hard to \n", "know whether it's a string or a integer, so you cannot choose a proper \n", "operation for them. And that comes a error."

# 9 - 
# ------------------------------------------------------------------------------

#print "'like' * -1", "is", 'like' * -1
#print "So multiplying a string by a negative number produce an ''"
#print "Some people believe it will produce an error, That's because\n", "they may think the amount of characters of a string should be 0 \n", "or positive."
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值