Tip of the day
News
Instructions
Objective
Write a python homework program to implement string manipulation.
Requirements and Specifications
Introduction:
Assignments evaluates understanding student knowledge of manipulating string
Instructions:
- Create a Python code file named M6HW_Digit Reading_FirstLast.py (replace "FirstLast" with your own name)
- Add a title comment block to the top of the new Python file using the following form
- Write a program that asks the user to enter a string that contains at least 2 digits.
- The program should count and display number of digits in string ( 60 points)
- In addition to displaying number of digits in strng, the program should display SUM of all the digits in the string.(30 points)
# A brief description of the project
# Date
# CSC121 – Digits in String
# Your Name
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 numbersdef string_num(test):temp = "0"Sum = 0# read the input stringfor digit in test:# if current character is a digitif (digit.isdigit()):temp += digit# if current character is an alphabetelse:# increment SumSum += int(temp)# reset temporary string to emptytemp = "0"return Sum + int(temp)# check if the count of the intgers > 2 numbersdef 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))# testtest = "I traveled 2 times in the past 3 days "# check if the count of the intgers > 2 numbersif 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.
Python
Word Count
4091 Words
Writer Name:Walter Parkes
Total Orders:2387
Satisfaction rate:
Python
Word Count
2184 Words
Writer Name:Dr. Jesse Turner
Total Orders:2365
Satisfaction rate:
Python
Word Count
6429 Words
Writer Name:Dr. Olivia Campbell
Total Orders:753
Satisfaction rate:
Python
Word Count
5883 Words
Writer Name:Dr. David Adam
Total Orders:489
Satisfaction rate:
Python
Word Count
5849 Words
Writer Name:Dr. Nicholas Scott
Total Orders:642
Satisfaction rate:
Python
Word Count
6162 Words
Writer Name:Professor Liam Mitchell
Total Orders:932
Satisfaction rate:
Python
Word Count
3640 Words
Writer Name:Professor Daniel Mitchell
Total Orders:465
Satisfaction rate:
Python
Word Count
4343 Words
Writer Name:Prof. Jackson Ng
Total Orders:627
Satisfaction rate:
Python
Word Count
7272 Words
Writer Name:Dr. Jennifer Carter
Total Orders:879
Satisfaction rate:
Python
Word Count
4577 Words
Writer Name:Dr. Sophia Nguyen
Total Orders:900
Satisfaction rate:
Python
Word Count
4145 Words
Writer Name:Dr. Isabella Scott
Total Orders:754
Satisfaction rate:
Python
Word Count
4193 Words
Writer Name:Dr. Isabella Scott
Total Orders:754
Satisfaction rate:
Python
Word Count
4165 Words
Writer Name:Dr. Ashley
Total Orders:685
Satisfaction rate:
Python
Word Count
4176 Words
Writer Name:Prof. Jackson Ng
Total Orders:627
Satisfaction rate:
Python
Word Count
3922 Words
Writer Name:Dr. Chloe Mitchell
Total Orders:957
Satisfaction rate:
Python
Word Count
4091 Words
Writer Name:Glenn R. Maguire
Total Orders:714
Satisfaction rate:
Python
Word Count
4747 Words
Writer Name:Dr. Sophia Nguyen
Total Orders:900
Satisfaction rate:
Python
Word Count
4594 Words
Writer Name:Dr. Samantha Benet
Total Orders:812
Satisfaction rate:
Python
Word Count
6716 Words
Writer Name:Dr. Isabella Scott
Total Orders:754
Satisfaction rate:
Python
Word Count
4347 Words
Writer Name:Prof. James Harper
Total Orders:664
Satisfaction rate: