Hướng dẫn classes and objects 1 task 2 hackerrank solution python fresco play - lớp và đối tượng 1 nhiệm vụ 2 hackerrank giải pháp python bích họa chơi

Fresco Play Chức năng và OOPS Hacker xếp hạng trên & NBSP;

Phòng thí nghiệm 1: Python 3 :: Chức năng và OOPS | 1 | Phương thức chuỗi

# LAB 1 : Python 3 - Functions and OOPs | 1 | String Methods

#!/bin/python3

import math
import os
import random
import re
import sys


def stringmethod[para, special1, special2, list1, strfind]:
    

    # Task 1 : Remove all the special characters from "para" specified  in "special1" and save them in the variable "word1"

    word1=re.sub[f"[{special1}]", "", para]
    

    # Task 2 : Get the first 70 characters from "word1", reverse the string, save it in variable "rword2", and print it.

    #rword2=word1[69::-1]

    rword2=word1[:70][::-1]
    print[rword2]
    

    # Task 3 : Remove all the wide spaces from "rword2", join the character using the special character specified in "special2", and print the joint string.

    temp=rword2.replace[" ",""].strip[] 
    temp=special2.join[temp]
    print[temp]   

    

    #Task 4 : If every string from list1 is present in para, then formate the print statement as follow:

    #               Every string in {list1} were present
    #         else
    #               Every String in {list1} were not present



    if all [ list1_item in para for list1_item in list1]  :
      print[f"Every string in {list1} were present"]
    else:
      print[f"Every string in {list1} were not present"]        

    

    # Task 5 : Split every word from word1 and print the first 20 strings as a list.

    s=word1.split[]
    print[s[:20]]


    #Task 6 : Calculate the less frequently used words whose count 

Bài Viết Liên Quan

Chủ Đề