{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"请输入一段英文:asdasdasdas\n",
"不是回文序列\n",
"1001,1008,1015,1022,1029,1036,1043,1057,1064,1071,1078,1085,1092,1099,1106,1113,1127,1134,1141,1148,1155,1162,1169,1176,1183,1197,1204,1211,1218,1225,1232,1239,1246,1253,1267,1274,1281,1288,1295,1302,1309,1316,1323,1337,1344,1351,1358,1365,1372,1379,1386,1393,1407,1414,1421,1428,1435,1442,1449,1456,1463,1477,1484,1491,1498,1505,1512,1519,1526,1533,1547,1554,1561,1568,1575,1582,1589,1596,1603,1617,1624,1631,1638,1645,1652,1659,1666,1673,1687,1694,1701,1708,1715,1722,1729,1736,1743,1757,1764,1771,1778,1785,1792,1799,1806,1813,1827,1834,1841,1848,1855,1862,1869,1876,1883,1897,1904,1911,1918,1925,1932,1939,1946,1953,1967,1974,1981,1988,1995,2002,2009,2016,2023,2037,2044,2051,2058,2065,2072,2079,2086,2093,2107,2114,2121,2128,2135,2142,2149,2156,2163,2177,2184,2191,2198,2205,2212,2219,2226,2233,2247,2254,2261,2268,2275,2282,2289,2296,2303,2317,2324,2331,2338,2345,2352,2359,2366,2373,2387,2394,2401,2408,2415,2422,2429,2436,2443,2457,2464,2471,2478,2485,2492,2499,2506,2513,2527,2534,2541,2548,2555,2562,2569,2576,2583,2597,2604,2611,2618,2625,2632,2639,2646,2653,2667,2674,2681,2688,2695,2702,2709,2716,2723,2737,2744,2751,2758,2765,2772,2779,2786,2793,2807,2814,2821,2828,2835,2842,2849,2856,2863,2877,2884,2891,2898,2905,2912,2919,2926,2933,2947,2954,2961,2968,2975,2982,2989,2996,3003,3017,3024,3031,3038,3045,3052,3059,3066,3073,3087,3094,3101,3108,3115,3122,3129,3136,3143,3157,3164,3171,3178,3185,3192,3199\n"
]
}
],
"source": [
"#1. 對用戶輸入的一段英文,判斷是否為回文序列(正读反读都相同,不區分大小寫)。\n",
"def rev(str1):\n",
" if str1[::-1] ==str1:\n",
" print(\"是回文序列\")\n",
" else:\n",
" print(\"不是回文序列\")\n",
"str2 = input(\"请输入一段英文:\")\n",
"str2=str2.upper()\n",
"output= rev(str2)\n",
"\n",
"#2. Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 10, between 1000 and 3200 (both included). The numbers obtained should be printed in a comma-separated sequence on a single line.\n",
"s=[]\n",
"for i in range(1000,3200):\n",
" if i%7 == 0:\n",
" if i%10 != 0:\n",
" s.append(str(i)) \n",
"print(','.join(s))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
研究设计与分析作业(1)
最新推荐文章于 2022-03-19 18:21:37 发布