python-3.x

Randomly capitalize letters in string [duplicate]

 ̄綄美尐妖づ 提交于 2021-02-08 12:21:16
问题 This question already has answers here : How do I modify a single character in a string, in Python? (4 answers) Closed 2 years ago . I want to randomly capitalize or lowercase each letter in a string. I'm new to working with strings in python, but I think because strings are immutable that I can't do the following: i =0 for c in sentence: case = random.randint(0,1) print("case = ", case) if case == 0: print("here0") sentence[i] = sentence[i].lower() else: print("here1") sentence[i] = sentence

No module named future

强颜欢笑 提交于 2021-02-08 12:18:53
问题 I am running a telegram bot in python and i am using python3.6 on raspbian ( pi3 ) Below is my imports: from __future__ import (absolute_import, division, print_function, unicode_literals) from builtins import ( bytes, dict, int, list, object, range, str, ascii, chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) from uuid import uuid4 import re import telegram from telegram.utils.helpers import escape_markdown from telegram import InlineQueryResultArticle, ParseMode, \

No module named future

笑着哭i 提交于 2021-02-08 12:17:59
问题 I am running a telegram bot in python and i am using python3.6 on raspbian ( pi3 ) Below is my imports: from __future__ import (absolute_import, division, print_function, unicode_literals) from builtins import ( bytes, dict, int, list, object, range, str, ascii, chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) from uuid import uuid4 import re import telegram from telegram.utils.helpers import escape_markdown from telegram import InlineQueryResultArticle, ParseMode, \

Unable to use pypdf module

故事扮演 提交于 2021-02-08 12:16:22
问题 I have installed the pyPdf module successfully using the command pip install pydf but when I use the module using the import command I get the following error: enC:\Anaconda3\lib\site-packages\pyPdf\__init__.py in <module>() 1 from pdf import PdfFileReader, PdfFileWriter 2 __all__ = ["pdf"] ImportError: No module named 'pdf' What should I do? I have installed the pdf module as well but still the error does not go away. 回答1: This is a problem of PyPDF, which does not occur in PyPDF2. Actually,

MIT programming in python Problem Set 1 Part C

守給你的承諾、 提交于 2021-02-08 12:13:39
问题 Following is the problem set from MIT opencourseware Part C: Finding the right amount to save away Your semi­annual raise is .07 (7%) Your investments have an annual return of 0.04 (4%) The down payment is 0.25 (25%) of the cost of the house The cost of the house that you are saving for is $1M. I am now going to try to find the best rate of savings to achieve a down payment on a $1M house in 36 months. And I want your savings to be within $100 of the required down payment.I am stuck with the

Class takes no arguments (1 given) [duplicate]

雨燕双飞 提交于 2021-02-08 12:13:17
问题 This question already has answers here : Python interpreter error, x takes no arguments (1 given) (4 answers) “<method> takes no arguments (1 given)” but I gave none (3 answers) Python:Function takes no arguments (2 answers) Closed 3 years ago . class MyClass: def say(): print("hello") mc = MyClass() mc.say() I am getting error: TypeError: say() takes no arguments (1 given) . What I am doing wrong? 回答1: This is because methods in a class expect the first argument to be self . This self

Python - find a substring between two strings based on the last occurence of the later string

£可爱£侵袭症+ 提交于 2021-02-08 12:12:07
问题 I am trying to find a substring which is between to strings. The first string is <br> and the last string is <br><br> . The first string I look for is repetitive, while the later string can serve as an anchor. Here is an example: <div class="linkTabBl" style="float:left;padding-top:6px;width:240px"> Anglo American plc <br> 20 Carlton House Terrace <br> SW1Y 5AN London <br> United Kingdom <br><br> Phone : +44 (0)20 7968 8888 <br> Fax : +44 (0)20 7968 8500 <br> Internet : <a class="pageprofil

Python - find a substring between two strings based on the last occurence of the later string

半城伤御伤魂 提交于 2021-02-08 12:11:44
问题 I am trying to find a substring which is between to strings. The first string is <br> and the last string is <br><br> . The first string I look for is repetitive, while the later string can serve as an anchor. Here is an example: <div class="linkTabBl" style="float:left;padding-top:6px;width:240px"> Anglo American plc <br> 20 Carlton House Terrace <br> SW1Y 5AN London <br> United Kingdom <br><br> Phone : +44 (0)20 7968 8888 <br> Fax : +44 (0)20 7968 8500 <br> Internet : <a class="pageprofil

EOF while parsing

假装没事ソ 提交于 2021-02-08 12:08:53
问题 def main(): NUMBER_OF_DAYS = 10 NUMBER_OF_HOURS = 24 data = [] for i in range(NUMBER_OF_DAYS): data.append([]) for j in range(NUMBER_OF_HOURS): data[i].append([]) data[i][j].append(0) data[i][j].append(0) for k in range(NUMBER_OF_DAYS * NUMBER_OF_HOURS): line = input().strip().split() day = eval(line[0]) hour = eval(line[1]) temperature = eval(line[2]) humidity = eval(line[3]) data[day - 1][hour - 1][0] = temperature data[day - 1][hour - 1][1] = humidity for i in range(NUMBER_OF_DAYS):

EOF while parsing

江枫思渺然 提交于 2021-02-08 12:06:13
问题 def main(): NUMBER_OF_DAYS = 10 NUMBER_OF_HOURS = 24 data = [] for i in range(NUMBER_OF_DAYS): data.append([]) for j in range(NUMBER_OF_HOURS): data[i].append([]) data[i][j].append(0) data[i][j].append(0) for k in range(NUMBER_OF_DAYS * NUMBER_OF_HOURS): line = input().strip().split() day = eval(line[0]) hour = eval(line[1]) temperature = eval(line[2]) humidity = eval(line[3]) data[day - 1][hour - 1][0] = temperature data[day - 1][hour - 1][1] = humidity for i in range(NUMBER_OF_DAYS):