最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

加拿大瑞爾森大學(xué) Python習(xí)題 Lab 3

2023-08-17 09:04 作者:逃跑的叮當(dāng)貓  | 我要投稿

Lab 3??CPS?106

?

?

This lab helps you practice string manipulation and recursive implementation.

?

1. ??You have written an essay that should?be?at?least?five pages?long,?but?it?is?only?4.5?pages.?You ??decide?to?use?your?new?python?skills?to?stretch?it?out?by?putting?spaces?between?each?letter?and the next. Write a function that takes?a?string?and?a?number?and prints?out?the?string?with?number of spaces between each pair of?letters.

def spacedout(str,?numSpaces)

For example spacedout(“It was a dark and stormy night”,?1)?returns

“I t??w a s ??a ??d a?r?k ??a?n?d??s?t?o?r?m y ??n i?g h?t”

?

2. ??Write a python program that returns the reverse of?a given string.

?

def?reverse(str1)

?

For?example reverse(“I am here”) returns?“ereh ma?I”. Using?this,?write?a?function?that?checks?if?a given string is a palindrome.

?

def isPalindrome(str1)

?

3. ??Write?a recursive function that?prints?all?the permutations?of a?given?string.?For?example,?for?the input “abcd” the?function should print:

?

abcd,?abdc,?acbd,?acdb,?adbc,?adcb,?bacd,?badc,?bcad,?bcda,?bdac,?bdca,?cabd,?cadb,?cbad,?cbda,?cdab, cdba, dabc, dacb,?dbac,?dbca,?dcab,?dcb

?

4. ??Given?an?integer?n,?write?a?python?program?that?finds?the?digit?with?the?highest?number?of

occurrences in n. For example, for n =?823778823478234768238?the program?should?return?8.

?

def findHighestOccur(n)

?

Test your program on the following inputs:

n?=?983254682376587235235

n?=?767347657623764765766665

n?=?923740923466234678666872628347666



代碼:

#3-1

# -*- coding: utf-8 -*-

"""

Created on Sun Jan? 8 10:17:36 2023


@author: pc

"""

str1 ='It was a dark and stormy night'

space2 = ' '


def spacedout(str, space):

? ? strResult = ''

? ? for a in str:

? ? ? ? a = a + space

? ? ? ? strResult = strResult + a

? ? ? ??

? ? print(strResult)


print(str1)

spacedout(str1, space2)


#3-1-2

# -*- coding: utf-8 -*-

"""

Created on Sun Jan? 8 10:29:47 2023


@author: pc

"""


s = 'It was a dark and stormy night'

? ??

def spacedout(str):

? ? addspace = ' '

? ? return addspace.join('It was a dark and stormy night')


print(spacedout(s))


# -*- coding: utf-8 -*-

"""

Created on Sun Jan? 8 10:49:56 2023


@author: pc

"""


# 3-2

# -*- coding: utf-8 -*-

"""

Created on Sun Jan? 8 10:17:36 2023


@author: pc

"""

str1 ='It was a dark and stormy night'

space2 = ' '


def spacedout(str, space):

? ? strResult = ''


? ? i? = 0

? ? for i in range(len(str)):

? ? ? ? a = str[len(str) - i - 1]

? ? ? ? strResult = strResult + a

? ? ? ??

? ? print(strResult)


print(str1)

spacedout(str1, space2)


#3-2?reverse

# -*- coding: utf-8 -*-

"""

Created on Sun Jan? 8 10:54:17 2023


@author: pc

"""


s = "I am here"


def reverse(str):

? ? n = len(str)

? ? l = ' '

? ? for i in range(n):

? ? ? ? l = l + str[n-i-1]

? ??

? ? return l


print(reverse(s))





加拿大瑞爾森大學(xué) Python習(xí)題 Lab 3的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
新闻| 额尔古纳市| 桐柏县| 吉木萨尔县| 板桥市| 阜宁县| 乐清市| 大方县| 宁陕县| 陆河县| 攀枝花市| 石家庄市| 永仁县| 古田县| 四子王旗| 曲阜市| 阿鲁科尔沁旗| 汨罗市| 宾阳县| 梓潼县| 贡觉县| 安新县| 黑水县| 南安市| 云浮市| 衡南县| 临颍县| 鄂尔多斯市| 隆尧县| 牡丹江市| 普兰县| 宜宾市| 宁强县| 临夏县| 吉首市| 河池市| 武强县| 双鸭山市| 清原| 沅陵县| 庆安县|