×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create a Program to Implement String Manipulation in Python Assignment Solution

July 03, 2024
Dr. Olivia Campbell
Dr. Olivia
🇺🇸 United States
Python
Dr. Olivia Campbell holds a Ph.D. in Computer Science from the University of Cambridge. With over 800 completed assignments, she specializes in developing complex Python applications, including fitness trackers and exercise planners. Dr. Campbell's expertise lies in algorithm design and data analysis, ensuring optimal performance and accuracy in every project she undertakes.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Ensure you understand the dataset thoroughly before starting your machine learning assignment. Visualize the data, check for missing values, and identify patterns or anomalies to guide your model-building process effectively.
News
In 2024, universities have introduced new programming courses focusing on cybersecurity, machine learning, and artificial intelligence to better prepare students for modern IT careers.

Instructions

Objective
Write a python homework program to implement string manipulation.

Requirements and Specifications

Introduction:
Assignments evaluates understanding student knowledge of manipulating string
Instructions:
  1. Create a Python code file named M6HW_Digit Reading_FirstLast.py (replace "FirstLast" with your own name)
  2. Add a title comment block to the top of the new Python file using the following form
  3. # A brief description of the project

    # Date

    # CSC121 – Digits in String

    # Your Name

  4. Write a program that asks the user to enter a string that contains at least 2 digits.
  5. The program should count and display number of digits in string ( 60 points)
  6. In addition to displaying number of digits in strng, the program should display SUM of all the digits in the string.(30 points)
For example, if user enters "I traveled 2 times in the past 3 days ". The program should notify the user that the string contains 2 digits ( 2 and 3) and that the sum of both is 5.
Submit your finished code solution file(s) through the assignment link below
Grading criteria:
  • Refer to above
  • 10 points for comment/ pseudocode
Note : ONLY USE PROGRAMMING METHODS LEARNED IN CLASS. If submission doesn't comply, you will get a grade of "1".
Source Code
# Python program to calculate sum of numbers present in a string
# Date : 08-04-2022
# CSC121 – Digits in String
# Your Name
#sum the integers numbers
def string_num(test):
temp = "0"
Sum = 0
# read the input string
for digit in test:
# if current character is a digit
if (digit.isdigit()):
temp += digit
# if current character is an alphabet
else:
# increment Sum
Sum += int(temp)
# reset temporary string to empty
temp = "0"
return Sum + int(temp)
# check if the count of the intgers > 2 numbers
def check(s):
nums = []
k = ""
for i in range(len(s)):
if ord(s[i]) > 47 and ord(s[i]) < 58:
k += s[i]
else:
if(k != ""):
nums.append(int(k))
k = ""
if(k != ""):
nums.append(int(k))
return len(set(nums))
# test
test = "I traveled 2 times in the past 3 days "
# check if the count of the intgers > 2 numbers
if check(test)<2:
print("the count of the integers is less than 2")

Related Samples

Discover our Python Assignments Sample Section for comprehensive programming solutions. Access step-by-step explanations and code samples ranging from introductory to advanced topics. Perfect for students seeking clarity and proficiency in Python programming. Enhance your understanding and excel in your assignments effortlessly.