C# The name "..." does not exist in the current context - c#

namespace ICNumber
{
class Program
{
static void Main(string[] args)
{
Console.Write("Please enter your Singapore IC starting with T:");
string ICnumber = Convert.ToString(Console.ReadLine());
int totalsum = 0;
for (int k = 1; k < 8; k++)
{
int number = ICnumber.IndexOf(ICnumber, k);
int digitsum = 0;
if (k is 1)
digitsum = number * 2;
if (k is 2)
digitsum = number * 7;
if (k is 3)
digitsum = number * 6;
if (k is 4)
digitsum = number * 5;
if (k is 5)
digitsum = number * 4;
if (k is 6)
digitsum = number * 3;
if (k is 7)
digitsum = number * 2;
totalsum = totalsum + digitsum;
}
int validcheck = (totalsum + 4) % 11;
string Validcheck = Convert.ToString(validcheck);
int letter = ICnumber.IndexOf(ICnumber, 8);
string Letter = Convert.ToString(letter);
if (Validcheck == "0" && Letter == "J")
{
string validity = "Valid";
}
if (Validcheck == "1" && Letter =="Z")
{
string validity = "Valid";
}
if (Validcheck == "2" && Letter =="I")
{
string validity = "Valid";
}
if (Validcheck == "3" && Letter =="H")
{
string validity = "Valid";
}
if (Validcheck == "4" && Letter =="G")
{
string validity = "Valid";
}
if (Validcheck == "5" && Letter =="F")
{
string validity = "Valid";
}
if (Validcheck == "6" && Letter =="E")
{
string validity = "Valid";
}
if (Validcheck =="7" && Letter =="D")
{
string validity = "Valid";
}
if (Validcheck =="8" && Letter =="C")
{
string validity = "Valid";
}
if (Validcheck =="9" && Letter =="B")
{
string validity = "Valid";
}
if (Validcheck =="10" && Letter =="A")
{
string validity = "Valid";
}
else
{
string validity = "False";
}
string Validity = validity;
}
}
}
Why is it that i cant use the variable validity?

Because validity is local to the scope of the if's/else's. You can only use a variable inside of the curly brackets you define it in (by writing the datatype in front of the name). This is how to declare the variable in the function scope and then just reference if inside the if's and else's
namespace ICNumber
{
class Program
{
static void Main(string[] args)
{
Console.Write("Please enter your Singapore IC starting with T:");
string ICnumber = Convert.ToString(Console.ReadLine());
int totalsum = 0;
for (int k = 1; k < 8; k++)
{
int number = ICnumber.IndexOf(ICnumber, k);
int digitsum = 0;
if (k == 1)
digitsum = number * 2;
if (k == 2)
digitsum = number * 7;
if (k == 3)
digitsum = number * 6;
if (k == 4)
digitsum = number * 5;
if (k == 5)
digitsum = number * 4;
if (k == 6)
digitsum = number * 3;
if (k == 7)
digitsum = number * 2;
totalsum = totalsum + digitsum;
}
int validcheck = (totalsum + 4) % 11;
string Validcheck = Convert.ToString(validcheck);
int letter = ICnumber.IndexOf(ICnumber, 8);
string Letter = Convert.ToString(letter);
string validity=""; //declare the variable here
if (Validcheck == "0" && Letter == "J")
{
validity = "Valid";//remove the keyword string. If you use the keyword you create a new variable (different from the one above)
}
else if (Validcheck == "1" && Letter =="Z")
{
validity = "Valid"; //keep on referencing the variable everywhere you need it
}
else if (Validcheck == "2" && Letter =="I")
{
validity = "Valid";
}
else if (Validcheck == "3" && Letter =="H")
.
.
.

You need to declare the variable validity outside of your if blocks. Since C# has block level scoping, each of your string validity =... statements is actually declaring a different variable named validity that only exists within that scope. When you're declaring the validity variable alongside validCheck:
int validcheck = (totalsum + 4) % 11;
string Validcheck = Convert.ToString(validcheck);
string validity = string.Empty;
And then updating each of the assignments to not include the typename:
if (Validcheck =="7" && Letter =="D")
{
validity = "Valid";
}

Variables in C# have block scope. If you declare a variable inside the block body of an if statement, it will only exist there.
Declare your variable outside the if statements. There is also a logic error in your code - the else at the end is attached only to the last if, so in order for your approach to work, you would need to use else if for the intermediate ifs:
string validity = null;
if (Validcheck == "0" && Letter == "J")
{
validity = "Valid";
}
else if (Validcheck == "1" && Letter =="Z")
{
validity = "Valid";
}
else if (Validcheck == "2" && Letter =="I")
{
validity = "Valid";
}
else if (Validcheck == "3" && Letter =="H")
{
validity = "Valid";
}
else if (Validcheck == "4" && Letter =="G")
{
validity = "Valid";
}
else if (Validcheck == "5" && Letter =="F")
{
validity = "Valid";
}
// .... etc.
else {
validity = "False"
}
string Validity = validity;
All of those if statements are also extremely redundant and could be replaced with a single if statement with one large condition.

You keep declaring the variable validity all the time. Declare it once then assign it. Also make it bool
I'd also consider a pre declared array or dictionary of valid combinations so you can just look up what you have in a couple of lines of code.

You have to declare string validity 1st before :
string validity = "";
if (Validcheck == "0" && Letter == "J")
{
validity = "Valid"
}...

Related

How to stop a while loop? C#

I am very new to C# and while loops. Does anyone know how to stop it? It keeps printing the first if-statement. Here is the code:
const int Year = 400;
const int LeapYear = 4;
const int NoLeapYear = 100;
int input = 0;
input = int.Parse(Console.ReadLine());
while (input != 0)
{
Console.WriteLine("Enter a number: ");
if (input > 0 && input % LeapYear == 0 || input % Year == 0)
{
Console.WriteLine($"{input} is a leap year.");
}
if (input > 0 && input % NoLeapYear != 0)
{
Console.WriteLine($"{input} is not a leap year.");
}
if (input < 0)
{
Console.WriteLine("Year must be positive!");
}
if (input == 0)
{
Console.WriteLine("End of program");
}
}
You have to read the input inside the while loop:
const int Year = 400;
const int LeapYear = 4;
const int NoLeapYear = 100;
int input = -1; // initialize to something different than zero, to enter the while loop (or use do while loop instead of while loop)
while (input != 0)
{
Console.WriteLine("Enter a number: ");
input = int.Parse(Console.ReadLine()); // you were missing this line
if (input > 0 && input % LeapYear == 0 || input % Year == 0)
{
Console.WriteLine($"{input} is a leap year.");
}
if (input > 0 && input % NoLeapYear != 0)
{
Console.WriteLine($"{input} is not a leap year.");
}
if (input < 0)
{
Console.WriteLine("Year must be positive!");
}
if (input == 0)
{
Console.WriteLine("End of program");
}
}
Consider using a do while loop in this case.
If you are using loop just and break to true statement It will breaks it
while (input != 0) {
conditions;
break; // Breaks the loop
}
Use the break; keyword to stop any loop in C# not just C# in many languages also break is used to stop loops
Or,
Satisfy the condition to opposite of what you have it will break/stop the loop
use break (https://www.w3schools.com/cs/cs_break.php)
int i = 0;
while (i < 10)
{
Console.WriteLine(i);
i++;
if (i == 4)
{
break;
}
}

Check patterns of 5 in password "12345", "abcde"

I'm trying to validate a password string in a .NET for sequential patterns (forward or reverse) with numbers or letters of 5 or more.
Examples of patterns that will not be accepted:
"ABCDE",
"12345",
"54321",
"edcba"
I cannot find a decent regex pattern that handles finding the characters in order, currently just returning any sequence of 5 letters or numbers:
public bool CheckForSequence(string input)
{
return Regex.IsMatch(input.ToUpper(), #"([A-Z])(?!\1)([A-Z])(?!\1|\2)([A-Z])(?!\1|\2|\3)([A-Z])(?!\1|\2|\3|\4)([A-Z])") ||
Regex.IsMatch(input, #"([1-9])(?!\1)([1-9])(?!\1|\2)([1-9])(?!\1|\2|\3)([1-9])(?!\1|\2|\3|\4)([1-9])");
}
There are probably way better ways to do this, but, just for fun, I've made a simple brute-force algorithm:
bool CheckForSequence(string inp) {
bool InRange(int c) {
const int minLower = (int)'a';
const int maxLower = (int)'z';
const int minUpper = (int)'A';
const int maxUpper = (int)'Z';
const int minNumber = (int)'0';
const int maxNumber = (int)'9';
return (c >= minLower && c <= maxLower) || (c >= minUpper && c <= maxUpper) || (c >= minNumber && c <= maxNumber);
}
if(inp.Length < 5) return false;
for(var i = 0; i < inp.Length - 4; i++)
{
var c = (int)inp[i];
if(InRange(c))
{
var vM = c;
int x;
for(x = i+1; x < i + 5; x++)
{
if(inp[x] != vM+1 || !InRange(inp[x])) break;
vM++;
}
if(x == i+5) return true;
for(x = i+1; x < i + 5; x++)
{
if(inp[x] != vM-1 || !InRange(inp[x])) break;
vM--;
}
if(x == i+5) return true;
}
}
return false;
}
You can see it in action in this fiddle
Wiktor is correct - regex is the wrong tool for this.
Here's one possible implementation:
public static class SequenceChecker
{
private static char MapChar(char c) => c switch
{
>= '0' and <= '9' => c,
>= 'A' and <= 'Z' => c,
>= 'a' and <= 'z' => (char)(c - 'a' + 'A'),
_ => default,
};
private static bool IsSequence(ReadOnlySpan<char> input)
{
char x = MapChar(input[0]);
if (x == default) return false;
char y = MapChar(input[1]);
if (y == default) return false;
int direction = y - x;
if (Math.Abs(direction) != 1) return false;
for (int index = 2; index < input.Length; index++)
{
x = y;
y = MapChar(input[index]);
if (y == default) return false;
int nextDirection = y - x;
if (nextDirection != direction) return false;
}
return true;
}
public static bool ContainsSequence(string input, int sequenceLength = 5)
{
if (sequenceLength < 2) throw new ArgumentOutOfRangeException(nameof(sequenceLength));
if (input is null) return false;
if (input.Length < sequenceLength) return false;
for (int startIndex = 0; startIndex < 1 + input.Length - sequenceLength; startIndex++)
{
if (IsSequence(input.AsSpan(startIndex, sequenceLength)))
{
return true;
}
}
return false;
}
}
Just to add to the plethora of solutions posted so far:
public static int LongestAscendingOrDescendingRun(string s)
{
if (s.Length <= 1)
return 0;
int longest = 0;
int current = 0;
bool ascending = false;
for (int i = 1; i < s.Length; i++)
{
bool isAscending () => s[i]-s[i-1] == +1;
bool isDescending() => s[i]-s[i-1] == -1;
if (current > 0)
{
if (ascending)
{
if (isAscending())
{
longest = Math.Max(longest, ++current);
}
else // No longer ascending.
{
current = 0;
}
}
else // Descending.
{
if (isDescending())
{
longest = Math.Max(longest, ++current);
}
else // No longer descending.
{
current = 0;
}
}
}
else // No current.
{
if (isAscending())
{
ascending = true;
current = 2;
longest = Math.Max(longest, current);
}
else if (isDescending())
{
ascending = false;
current = 2;
longest = Math.Max(longest, current);
}
}
}
return longest;
}
Like Wiktor has already said, regex isn't a good way to do this. You could find the difference between consecutive characters of the string, and complain if you find a sequence of four or more ones (or -1s).
public bool CheckForSequence(string pass)
{
int curr_diff = 0; // The difference between the i-1th and i-2th character
int consec_diff = 0; // The number of consecutive pairs having the same difference
for (int i = 1; i < pass.Length; i++)
{
int diff = pass[i] - pass[i - 1]; // The difference between the ith and i-1th character
if (Math.Abs(diff) == 1 && curr_diff == diff)
{
// If the difference is the same, increment consec_diff
// And check if the password is invalid
consec_diff++;
if (consec_diff >= 4)
return false;
}
else
{
// New diff. reset curr_diff and consec_diff
curr_diff = diff;
consec_diff = Math.Abs(diff)==1 ? 1 : 0;
// If the difference is 1, set consec_diff to 1 else 0
}
}
return consec_diff < 4;
}

How can do calculations inside a string?

How do i use operands in this code? What can i do to resolve this problem? Any suggestions or links to tutorials would be appreciated.
Operator '%' cannot be applied to operands of type 'string' 'int'
int i = 0;
double[] arr1 = new double[20];
for (i = 0; i < 20; i++)
{
Console.Write("Enter a number (0=stop): ");
var year = Console.ReadLine();
if (year == "0") break;
arr1[i] = int.Parse(year);
while (year != 0)
{
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
{
Console.WriteLine($"{year} is a leap year.");
}
else if (year < 0)
{
Console.WriteLine($"Year must be positive!");
}
else
{
Console.WriteLine($"{year} is not a leap year.");
}`
You are close. You are already parsing the string to an int. Just use that instead of the string year when doing your calculations. Also, I'm not sure what you're trying to do with that while loop but I don't think you need it. It seems to just cause your program to go in an infinite loop because while is evaluating year but there is no opportunity to change the year value within the while loop.
void Main()
{
int i = 0;
double[] arr1 = new double[20];
for (i = 0; i < 20; i++)
{
Console.Write("Enter a number (0=stop): ");
var line = Console.ReadLine();
int numYear = int.Parse(line);
arr1[i] = numYear;
string message = "" ;
if (line != "0")
{
if (numYear < 0)
{
message = "Year must be positive!";
}
else if ((numYear % 4 == 0) && (numYear % 100 != 0)) || (numYear % 400 == 0))
{
message = $"{numYear} is a leap year.");
}
else
{
message = $"{numYear} is not a leap year.");
}
Console.WriteLine(message);
}
}
}

How to convert user input to an int Array in c#

The closest thing I found to answering this question was converting several string inputs into an array using a for loop.
I just want to take 1 string and convert the first 7 digits into an int array.
This code takes integer values of characters and then tests them against the Unicode values to return true if it is valid or false to reiterate the while loop and ask for input again. When I do this with the Console.Read(); method, and put in an invalid value first, it will say that my code is invalid for 7 more iterations. That means console.Read() has to run 7 more times even if the string has valid input.
public static void GetDigits(ref int[] callNumberArray, ref bool valid)
{
Console.WriteLine("Please enter the code you wish to dial.");
while ( valid == false)
{//This loop will reiterate the read() function if the code is not valid.
valid = true;
for (int i = 0; i < 7; i++ )
{
if (i != 6 && i!= 5 && i != 5 && i != 4 && i != 3 && i != 2 && i != 1 && i != 0)
{
i = 0;
}
callNumberArray[i] = Console.Read();// I want to change this
}
for (int i = 0; i < 7; i++)
{
if (i != 6 && i != 5 && i != 5 && i != 4 && i != 3 && i != 2 && i != 1 && i != 0)
{
i = 0;
}
if (callNumberArray[0] == 53)
{
valid = false;
}
if (callNumberArray[i] < 49)
{
valid = false;
}
if (callNumberArray[i] > 57 && callNumberArray[i] < 65)
{
valid = false;
}
if (callNumberArray[i] > 90 && callNumberArray[i] < 97)
{
valid = false;
}
if (callNumberArray[i] > 122)
{
valid = false;
}
}
if (valid == false)
{
Console.WriteLine("You entered an invalid code. Please re-enter your code.");
}
}
I think you should use Regex, example:
MatchCollection matchList = Regex.Matches(Content, Pattern);
var list = matchList.Cast<Match>().Select(match => match.Value).ToList();
I just want to take 1 string and convert the first 7 digits into an int array.
string subString = Console.ReadLine().Substring(0,7);
//Check if the whole string is a parsable number
if(int.TryParse(subString) == false)
{
Console.WriteLine("Not a valid number...");
return;
}
//convert it an int[]
int[] values = subString.ToCharArray().Select( value => int.Parse(value.ToString())).ToArray();
That's it basically, if you want to do it character by character that's fine, too, but's it's far easier to check for a number using int.TryParse() or a regex [0-9] (per character) if you're confortable with that.
Not sure about the "algorithm" you wrote and I agree with Sergey Berezovskiy that the if's looks weird, anyway this should answer your specific question:
public static void GetDigits(ref int[] callNumberArray, ref bool valid)
{
Console.WriteLine("Please enter the code you wish to dial.");
while ( valid == false)
{//This loop will reiterate the read() function if the code is not valid.
valid = true;
for (int i = 0; i < 7; i++ )
{
if (i != 6 && i!= 5 && i != 5 && i != 4 && i != 3 && i != 2 && i != 1 && i != 0)
{
i = 0;
}
callNumberArray[i] = Console.Read();// I want to change this
}
for (int i = 0; i < 7; i++)
{
if(!valid) break;
if (i != 6 && i != 5 && i != 5 && i != 4 && i != 3 && i != 2 && i != 1 && i != 0)
{
i = 0;
}
if (callNumberArray[0] == 53)
{
valid = false;
}
if (callNumberArray[i] < 49)
{
valid = false;
}
if (callNumberArray[i] > 57 && callNumberArray[i] < 65)
{
valid = false;
}
if (callNumberArray[i] > 90 && callNumberArray[i] < 97)
{
valid = false;
}
if (callNumberArray[i] > 122)
{
valid = false;
}
}
if (valid == false)
{
Console.WriteLine("You entered an invalid code. Please re-enter your code.");
}
}
Here is method which prompts user to input phone number, denies invalid characters and shows current phone number with placeholder for numbers left to input:
private static int[] GetPhoneNumber(int phoneLength = 7)
{
List<int> phoneNumbers = new List<int>();
while (true)
{
EditorFor("Phone", String.Concat(phoneNumbers), phoneLength);
var key = Console.ReadKey(intercept: true);
if (key.Key == ConsoleKey.Escape)
return new int[0]; // return empty array if user cancelled input
var c = key.KeyChar;
if (!Char.IsDigit(c))
continue;
phoneNumbers.Add(Int32.Parse(c.ToString()));
if (phoneNumbers.Count == phoneLength)
{
EditorFor("Phone", String.Concat(phoneNumbers), phoneLength);
return phoneNumbers.ToArray();
}
}
}
Prompt for input:
private static void EditorFor(string label, string value, int length)
{
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(new String(' ', Console.WindowWidth));
Console.SetCursorPosition(0, Console.CursorTop);
int charactersLeftToInput = length - value.Length;
string placeholder = new String('*', charactersLeftToInput);
Console.Write("{0}: {1}{2}", label, value, placeholder);
Console.CursorLeft -= charactersLeftToInput;
}
Usage:
Console.WriteLine("Please enter the code you wish to dial.");
int[] code = GetPhoneNumber(); // if you want default length
Console:
Okay so After much deliberation I decided to use a separate Console.Read(); for each element in the array and now it's doing what I want it to do.
while ( valid == false)
{
valid = true;
callNumberArray[0] = Console.Read();
callNumberArray[1] = Console.Read();
callNumberArray[2] = Console.Read();
callNumberArray[3] = Console.Read();
callNumberArray[4] = Console.Read();
callNumberArray[5] = Console.Read();
callNumberArray[6] = Console.Read();
//etc etc...

Counting number of vowels in a string

I have a textbox where the user enters a random string. I want to count the number of vowels(A,E,I,O,U) in the string and show th results in the labelcontrol.
protected void Button1_Click(object sender, EventArgs e)
{
string EnterString;
EnterString = TextBox1.Text;
char ch1 = 'a';
char ch2 = 'e';
char ch3 = 'i';
char ch4 = 'o';
char ch5 = 'u';
int counta = 0;
int counte = 0;
int counti = 0;
int counto = 0;
int countu = 0;
char ch6 = 'A';
char ch7 = 'E';
char ch8 = 'I';
char ch9 = 'O';
char ch10 = 'U';
int countA = 0;
int countE = 0;
int countI = 0;
int countO = 0;
int countU = 0;
//const string vowels = "aeiou";
/* return value.Count(chr => vowels.Contains(char.ToLower(chr)));
return Value.Count()*/
int j = counta + counte + counti + counto + countu + countA + countE + countI + countO + countU;
foreach (char v in EnterString)
{
if (v == ch1) { counta++; j++; }
else if (v == ch2) { counte++; j++; }
else if (v == ch3) { counti++; j++; }
else if (v == ch4) { counto++; j++; }
else if (v == ch5) { countu++; j++; }
}
foreach (char v in EnterString)
{
if (v == ch6) { countA++; j++; }
else if (v == ch7) { countE++; j++; }
else if (v == ch8) { countI++; j++; }
else if (v == ch9) { countO++; j++; }
else if (v == ch10) { countU++; j++; }
}
Label1.Text = j.ToString();
}
You have this in your code:
const string vowels = "aeiou";
return value.Count(chr => vowels.Contains(char.ToLower(chr)));
That works, at least if your culture is US. So no idea why you commented it out in favor of the current monstrosity.
On a Turkish locale it will fail because the lower case of I is not i but ı (undotted). So if you define vowels as aeiouAEIOU you should use ToLowerInvariant.
But if you want to include other vowels (like Ä) I have no idea how to do that except by listing all the characters.
Full implementation:
int CountVowels(string value)
{
const string vowels = "aeiou";
return value.Count(chr => vowels.Contains(char.ToLowerInvariant(chr)));
}
Looks like you got the good code part from:
Counting vowels using switch
int vowel = 0;
Console.WriteLine("Please enter the string:");
string main = Console.ReadLine();
for (int j = 0; j < main.Length ; j++)
{
if (main[j] == 'a' || main[j] == 'A' || main[j] == 'e' || main[j] == 'E' || main[j] == 'i' || main[j] == 'I' || main[j] == 'o' || main[j] == 'O' || main[j] == 'u' || main[j] == 'U')
{
vowel++;
}
}
Console.WriteLine("Number of vowels in sentence is :"+ vowel);
Console.ReadLine();
Console.WriteLine("Please input your text: ")
mystring = Console.ReadLine
For i = 1 To mystring.Length
Console.Write((mystring(i - 1)) & ",")
isItAVowel = False
If mystring(i - 1) = "a" Or mystring(i - 1) = "A" Then isItAVowel = True
If mystring(i - 1) = "e" Or mystring(i - 1) = "E" Then isItAVowel = True
If mystring(i - 1) = "i" Or mystring(i - 1) = "I" Then isItAVowel = True
If mystring(i - 1) = "o" Or mystring(i - 1) = "O" Then isItAVowel = True
If mystring(i - 1) = "u" Or mystring(i - 1) = "U" Then isItAVowel = True
If isItAVowel Then
This could help good luck
private void button1_Click(object sender, EventArgs e)
{
string EnterString;
EnterString = textBox1.Text;
const string vowels = "aeiou";
label1.Text = EnterString.Count(myString => vowels.Contains(char.ToLowerInvariant(myString))).ToString();
}
public static void Main()
{
char[] sentence = new char[100];
int i, vowels = 0, consonants = 0, special = 0, n;
Console.WriteLine("Enter the Length of the sentence \n");
n = int.Parse(Console.ReadLine());
for (i = 0; i < n; i++)
{
sentence[i] = Convert.ToChar(Console.Read());
}
for (i = 0; sentence[i] != '\0'; i++)
{
if ((sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] ==
'i' || sentence[i] == 'o' || sentence[i] == 'u') ||
(sentence[i] == 'A' || sentence[i] == 'E' || sentence[i] ==
'I' || sentence[i] == 'O' || sentence[i] == 'U'))
{
vowels = vowels + 1;
}
else
{
consonants = consonants + 1;
}
if (sentence[i] == 't' || sentence[i] == '\0' || sentence[i] == ' ')
{
special = special + 1;
}
}
consonants = consonants - special;
Console.WriteLine("No. of vowels {0}", vowels);
Console.WriteLine("No. of consonants {0}", consonants);
Console.ReadLine();
Console.ReadLine();
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
set<char> vowels = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'};
while(t--)
{
string s;
int c = 0;
cin >> s;
for(char i : s)
if(vowels.find(i) != vowels.end())
++c;
cout << c << "\n";
}
return 0;
}
string vowelList = ("aeiouAEIOU");
int i = 0;
int j = 0;
int vowelCount = 0;
string main = textBox1.Text; /or Console.ReadLine();
while (j < main.Length)
{
while (i < vowelList.Length)
{
if (main[j] == vowelList[i])
{
vowelCount++;
}
i++;
}
j = j + 1;
i = 0;
}
label1.Text = ("Number of vowels in sentence is :" + vowelCount); /or Console.Writeline ("Number of vowels in sentence is: " + vowelCount
count = 0
string=input("Enter string:")
vowels = set("aeiouAEIOU")
for letter in string:
if letter in vowels:
count += 1
print("Count of the vowels is:")
print(count)

Categories