jeapedu 19 字符串算术运算习题答案
2018-02-27 15:04
375 查看
链接: https://pan.baidu.com/s/1eUlMJSI 密码: dk43
# 1 print jeapedu000~jeapedu100 # 2 count "c" in "aacacaac" * 100 count and pos # 3 random.randint(100000,999999) # 1) if 4 and 7 in it, otherwise drop the num # 2) when not 4 and 7 in it, whether 6 and 8 in it # 1 print jeapedu000~jeapedu100 #jeapedu000 #jeapedu001 #jeapedu009 #... #jeapedu010 #jeapedu011 #jeapedu099 #... #jeapedu100 # while i = 0 while i <= 100: if i < 10: print("jeapedu00" + str(i)) elif i < 100: print("jeapedu0" + str(i)) else: print("jeapedu" + str(i)) i +=1 # str.zfill(width) str method i = 0 while i <= 100: s = str(i) s = s.zfill(3) print("jeapedu" + s) #print("jeapedu" + str(i).zfill(3)) i += 1 # num formatting i = 0 while i <= 100: s = "%03d" %i print("jeapedu" + s) #print("jeapedu" + "%03d" %i) i += 1 # num format function i = 0 while i <= 100: s = "{0:03d}".format(i) print("jeapedu" + s) i += 1 # 2 count "c" in "aacacaac" * 100 count and pos s = "aacacaac" * 100 i = 0 count = 0 while i < len(s): if s[i] == "c": print("found", s[i], i) count += 1 i += 1 print(count) # 3 random.randint(100000,999999) # 1) if 4 and 7 in it, otherwise drop the num # 2) when not 4 and 7 in it, whether 6 and 8 in it import random i = 0 while i < 20: x = random.randint(100000,999999) s = str(x) j = 0 if "4" in s or "7" in s: print(s, end=' ') while j < len(s): if s[j] == "4" or s[j] == "7": print(s[j], j, end=' ') j += 1 elif "6" in s or "8" in s: print(s, end=' ') while j < len(s): if s[j] == "6" or s[j] == "8": print(s[j], j, end=' ') j += 1 print("") i += 1 import random x = random.randint(100000, 999999) print(x + 100, type(x), str(x), type(str(x))) s = str(x) i = 1 while i < 20: x = random.randint(100000, 999999) s = str(x) #if "4" in s: #print(i, "has 4 in", s) if "4" in s and "7" not in s: print(i, "has 4 in", s) else: print(i, s) i += 1
相关文章推荐
- jeapedu 29 字符串切片习题及答案
- jeapedu 26 字符串与两重循环习题2答案
- jeapedu 30 字符串切片习题答案编码
- jeapedu 24 字符串与两重循环习题答案
- [原创] C语言位运算和bit位操作程序题目答案 -- 谭浩强C语言习题答案
- 【LeetCode 67_字符串_算术运算】Add Binary
- java将字符串转换为算术运算
- JAVA--第十周作业编写之一个Teacher类负责给出算术题目,随机给出两个整数并进行运算,并判断回答者的答案是否正确;编写一个GUI类ComputerFrame,回答者可以通过GUI看到题目并给出
- C语言程序设计习题1-19 编写函数reverse(s),实现字符串的倒序,并用该函数每次颠倒一个输入行中的字符顺序
- java习题--字符串运算和拼接
- JS中的常用方法(算术运算、日期、字符串)(转)
- 【LeetCode 38_字符串_算术运算】Count and Say
- 与oc字符串有关的习题以及答案
- 小甲鱼Python教程第15讲--python字符串格式化笔记及习题答案
- 《笨办法学python》加分习题19——我的答案
- 小甲鱼Python教程第14讲--python字符串内置方法笔记及习题答案
- jeapedu 20 字符串习题答案
- c++primer(第五版) 第十四章 重载运算与类型转换习题答案
- 【零基础入门学习Python笔记003】插曲之变量和字符串|课习题答案
- 2017.07.12回顾 python mysql decimal case when漏掉一种情况 mysql字符串参与算术运算