main
.py
keyboard_arrow_up
School
University of North Carolina, Charlotte *
*We aren’t endorsed by this school
Course
5376
Subject
Computer Science
Date
Feb 20, 2024
Type
py
Pages
1
Uploaded by PrivateBadgerMaster993
# Count the number of vowels in a given string
def count_vowels(input_string):
vowels = 'aeiouAEIOU'
count = 0
for char in input_string:
if char in vowels:
count += 1
return count
# Convert string to title case using def
testing = 'atrium health'
print('testing vowels:', count_vowels(testing))
def title_case(input_string):
return input_string.title()
test = 'atrium health'
print('Original string:', test)
print('New string:', title_case(test))
# Use python code to demonstrate string length using for loop
def findLen(str):
counter = 0
for i in str:
counter += 1
return counter
str = 'novant'
print(findLen(str))
# Slicing strings
data = 'X-DSPAM-Confidence: 0.8475'
atpos = data.find(':')
host = data[atpos+1:]
print('Value:', float(host))
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
JAVASCRIPT QSTN
arrow_forward
. COMPLETE THE CODES.
arrow_forward
C++ Language
arrow_forward
Do Code.
arrow_forward
Name format: You must use String object and not StringBuffer or StringBuilder.
Many documents use a specific format for a person's name. Write a program that take one
Line as an input.
Example:
Scanner input = new Scanner(System.in);
System.out.println(“Enter firstName middleName lastName separated by at least one
blank, It may have more than one blank separating firstName middleName lastName.");
Input sample : Pat Silly Doe || Note these are separated by at least one blank.
String line = input.nextLine()
Ex: If the input is:
Pat Silly Doe
the output is:
Doe, P.S.
If the input has the form:
firstName lastName
the output is:
lastName, firstInitial.
Ex: If the input is:
Julia Clark
the output is:
Clark, J.
Please submit the .java source file and the sample run in a text file. Thanks
arrow_forward
If String str1 = new String("Final Exam");, the value
of str1.indexOf('x') is
arrow_forward
This application accepts an arbitrary number of user inputs. Every time this application receives a string, it should add the string to a growing string.Newly added strings should be added to the growing string at the index equal to the newly added string's length.
arrow_forward
Please do not use replace or any other string method
arrow_forward
Q: People often forget closing parentheses when entering formulas. Write a program that asks the user to enter a formula and prints out whether the formula has the same number of opening and closing parentheses.
Q: Write a program that asks the user to enter a word and prints out whether that word contains any vowels.
Q: Write a program that asks the user to enter a string. The program should create a new string called new_string from the user’s string such that the second character is changed to an asterisk and three exclamation points are attached to the end of the string. Finally, print new_string. Typical output is shown below: Enter your string: Qbert Q*ert!!!
Q: Write a program that asks the user to enter a string s and then converts s to lowercase, removes all the periods and commas from s, and prints the resulting string.
Q: Write a program that asks the user to enter a word and determines whether the word is a palindrome or not. A palindrome is a word that reads the same…
arrow_forward
String Matching): Write a program to use Horspool’s Algorithm to find the pattern in the string.
You can define two variables called Text and Pattern.
Please display shift table for that pattern and display the shift value for each step. If not match, display a message “Unsuccessful Search”. If match, display the index.
For example,
If Text =“BARD LOVED BANANAS” and Pattern=”BAOBAB”.
The result will be:
Shift Table: A=1, B=2, O=3, other=6
Shift 6, shift 2, shift 6, pattern not found
If Text=”BARD LOVED BABAOBABANAS” and Pattern=”BAOBAB”.
The result will be:
Shift Table: A=1, B=2, O=3, other=6
Shift 6, shift 2, shift 2, shift 3, pattern found at position 13
Language preferred is python
arrow_forward
Allowed libraries:
arrow_forward
String.ParseInt(m); will convert the integer value of m to a String
True
False
arrow_forward
Cyclops numbersdef is_cyclops(n):A nonnegative integer is said to be a cyclops number if it consists of an odd number of digits so that the middle (more poetically, the “eye”) digit is a zero, and all other digits of that number are nonzero. This function should determine whether its parameter integer n is a cyclops number, and return either True or False accordingly
n
Expected result
0
True
101
True
98053
True
777888999
False
1056
False
675409820
False
arrow_forward
most_frequent_word() takes a string as the input parameter and returns two values; the word that appears most frequently in that string and the total number of times that word appears in that string. In case of a tie, return the first word that appears in the string. Hint: you can use the unique_words function that you wrote in (4).
Sample outputs:>>> data = “chapter one hottest day summer so far drawing close drowsy silence lay over large square houses privet drive cars usually gleaming stood dusty drives lawns once emerald green lay parched yellowing”>>> word = most_frequent_word(data)>>> print(word)('lay', 2)>>> data_2 = "a cat in a hat and a big black bear on a big black rug">>> word = most_frequent_word(data_2)>>> print(word)('a', 4)
arrow_forward
Pls debug this pseudocode
// Program lets user input scores on four tests// Average is computed and letter grade is determined// Letter grades are based on 90 for an A, 80 for a B, and so onstart string name num score num NUM_TESTS = 4 num NUM_RANGES = 5 num RANGES[NUM_RANGES] = 90, 80, 70, 60, 0 string QUIT = "ZZZZZ" string GRADES[NUM_RANGES] = "A", "B", "C", "D", "F" num total num average num sub output "Enter student name or ", QUIT, " to quit " input name while name <> QUIT sub = 0 total = 0 while sub < NUM_TESTS output "Enter score " input score total = score endwhile sub = 0 while average < RANGES sub = sub + 1 endwhile letterGrade = GRADES[sub] output name, letterGrade output "Enter student name or ", QUIT, " to quit " input lettergrade endwhilestop
arrow_forward
This must be in PYTHON! Thank you!
arrow_forward
insert_substrings_into_string(s, substrs): This function takes a string s and a string substrs. The substrs string will contain 0 or more comma-separated substrings. The string s will contain text with 0 or more special placeholder character sequences. These placeholder character sequences will always begin with the percent character %, followed by one or more digits (which form a non- negative number). The function will create a new string from the original string s where all the placeholder character sequences in s are replaced by the substrings in the string substrs. The placeholder %0 should be replaced by the first substring in substrs (i.e., everything before the first comma, if such a comma exists). The placeholder %1 should be replaced by the second substring in substrs (i.e., everything between the first and second comma, if such a comma exists), and so on. The new string should then be returned.
Note: If a placeholder sequence refers to an invalid index (e.g., %10 when there…
arrow_forward
String orig_string is read from input. Assign variable sliced_saying with all the characters in orig_string, except for the last character.
arrow_forward
Target
The aim of this work is to use control structures
and loops. Read
carefully the problem and understand what
needs to be done. Read your description
is given and when you understand how it
works, then start designing its solution and
its implementation on the computer applying
the syntax and semantics of the language
Java programming.
Write a LongestDupSubstring.java program that
accepts a string as input
and compute and print the longest sub-string
displayed in two
times without overlap (see 5th
example for overlap). If there are more
from one of such sub-strings, the program
displays the first one it finds as well
the number of characters in the substring. If
there is no substring that
appears 2 times, then the program will not print
anything.
Execution examples (the user's input is red and
the longer in length 2 substrings)
1 Example
Give a string: again and again
Longest substring: again
Longest substring size: 5
2 Example
Give a string: seven saints and seven dinners
Longest…
arrow_forward
Strings that contain ‘01’ as substrings at any place except at the beginning or at the end. It accepts 1010,110110, etc. but does not accept 01, 0110, 1101, 00, etc. Ʃ={0, 1}
arrow_forward
C language
arrow_forward
1.
This program reads one number, as a string, and assign it to String getData
Increment and display getData as integer and double
Only strings are to be read
2.
This program reads strings only
Read ten digits, such as 2345678923
store them in getData, which is a string
Display each value and it position in the string
arrow_forward
Option #1: String Values in Reverse Order
Assignment Instructions
Write a Python function that will accept as input three string values from a user. The method will return to the user a concatenation of the string values in reverse order. The function is to be called from the main method.
In the main method, prompt the user for the three strings.
arrow_forward
def validate_priority(priority): ''' validate the "priority" parameter Returns True if "priority" is a string containing a number 1-5 Returns False otherwise ''' if (priority.isdigit()): if (priority == 1): return True elif (priority == 2): return True elif (priority == 3): return True elif (priority == 4): return True elif (priority == 5): return True else: return False pass
value for "priority" must be a string that contains a number 1-5
this is my code
arrow_forward
i. L1 = {w | all strings start with 1 or ended with 0}
arrow_forward
Function SubStr( St As String) As String
Sum=1
for x=l to 8
if x mod 2 = 0 then
S=Mid(St, x, x*2)
Else
S=Mid(St, x, x+2)
End if
Next x
SubStr=S
End Function
Sub Cmd_Click()
Label.text= SubStr("Phones:987456124123456744")
End Sub
987456124
:9874561241
9874561241
98745612412
arrow_forward
In C language
arrow_forward
get_nth_word_from_string(s, n): This function takes a string s and a non-negative integer n as input. The string s may contain substrings of text separated by commas. The function should return the n’th comma-separated substring. We will start counting at 0, so if n=0, then the first substring should be returned (i.e., everything before the first comma, if there is such a comma); if n=1, then the second substring should be returned (i.e., everything between the first comma and second comma, if there is such a comma); and so on. If there is no n’th substring in s, then the empty string should be returned. Note: You may use the string count method in this function.
Note: If a space follows a comma, do not include the space as part of the substring to be returned.
arrow_forward
get_nth_word_from_string(s, n): This function takes a string s and a non-negative integer n as input. The string s may contain substrings of text separated by commas. The function should return the n’th comma-separated substring. We will start counting at 0, so if n=0, then the first substring should be returned (i.e., everything before the first comma, if there is such a comma); if n=1, then the second substring should be returned (i.e., everything between the first comma and second comma, if there is such a comma); and so on. If there is no n’th substring in s, then the empty string should be returned. Note: You may use the string count method in this function.
Note: If a space follows a comma, do not include the space as part of the substring to be returned.
>>> get_nth_word_from_string("dreary, pondered, weak, weary", 0)
'dreary'
arrow_forward
When I try another flight number besides the first one it returns invalid and why arent my set(1) spacing out correctly
#include
#include
#include
#include
#include
#include
using namespace std;
int main(){
string usern; //Declare string Usern
string passwrd; //Declare string passwrd
string _usern; //Declare string Usern
string _passwrd; //Declare string passwrd
string _fname;
string _lname;
string _time;
string _destination;
int ffn; //Declare ffn integer
int seats;
int flightno; //Declare flightno integer
int _ffn;
int _flightno; //Declare flightno integer
int _total_seats;
int _seats_available;
double _price;
double total; //Declare total variable
int attemptCount = 0;
string line = " ";
bool match_found = 0 ; //variable which hold 1 if match found
ifstream readFile1("accounts.dat");
ifstream readFile2("flights.dat");
bool match_found2 = 0;
while(getline(readFile2,line)) { //read file line by line till end of file
stringstream iss(line);
iss >> _flightno >>…
arrow_forward
c language
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Related Questions
- Do Code.arrow_forwardName format: You must use String object and not StringBuffer or StringBuilder. Many documents use a specific format for a person's name. Write a program that take one Line as an input. Example: Scanner input = new Scanner(System.in); System.out.println(“Enter firstName middleName lastName separated by at least one blank, It may have more than one blank separating firstName middleName lastName."); Input sample : Pat Silly Doe || Note these are separated by at least one blank. String line = input.nextLine() Ex: If the input is: Pat Silly Doe the output is: Doe, P.S. If the input has the form: firstName lastName the output is: lastName, firstInitial. Ex: If the input is: Julia Clark the output is: Clark, J. Please submit the .java source file and the sample run in a text file. Thanksarrow_forwardIf String str1 = new String("Final Exam");, the value of str1.indexOf('x') isarrow_forward
- This application accepts an arbitrary number of user inputs. Every time this application receives a string, it should add the string to a growing string.Newly added strings should be added to the growing string at the index equal to the newly added string's length.arrow_forwardPlease do not use replace or any other string methodarrow_forwardQ: People often forget closing parentheses when entering formulas. Write a program that asks the user to enter a formula and prints out whether the formula has the same number of opening and closing parentheses. Q: Write a program that asks the user to enter a word and prints out whether that word contains any vowels. Q: Write a program that asks the user to enter a string. The program should create a new string called new_string from the user’s string such that the second character is changed to an asterisk and three exclamation points are attached to the end of the string. Finally, print new_string. Typical output is shown below: Enter your string: Qbert Q*ert!!! Q: Write a program that asks the user to enter a string s and then converts s to lowercase, removes all the periods and commas from s, and prints the resulting string. Q: Write a program that asks the user to enter a word and determines whether the word is a palindrome or not. A palindrome is a word that reads the same…arrow_forward
- String Matching): Write a program to use Horspool’s Algorithm to find the pattern in the string. You can define two variables called Text and Pattern. Please display shift table for that pattern and display the shift value for each step. If not match, display a message “Unsuccessful Search”. If match, display the index. For example, If Text =“BARD LOVED BANANAS” and Pattern=”BAOBAB”. The result will be: Shift Table: A=1, B=2, O=3, other=6 Shift 6, shift 2, shift 6, pattern not found If Text=”BARD LOVED BABAOBABANAS” and Pattern=”BAOBAB”. The result will be: Shift Table: A=1, B=2, O=3, other=6 Shift 6, shift 2, shift 2, shift 3, pattern found at position 13 Language preferred is pythonarrow_forwardAllowed libraries:arrow_forwardString.ParseInt(m); will convert the integer value of m to a String True Falsearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT