0

Can any one convert c++ logic code to python logic code

// For this challenge you will determine if a pair of even numbers exists somewhere in a string. // have the function EvenPairs(str) take the str parameter being passed and determine if a pair of adjacent even numbers exists anywhere in the string. If a pair exists, return the string true, otherwise return false. For example: if str is "f178svg3k19k46" then there are two even numbers at the end of the string, "46" so your program should return the string true. Another example: if str is "7r5gg812" then the pair is "812" (8 and 12) so your program should return the string true. Logic: ------ string EvenPairs(string str) { int temp, count; // Loop through the string parameter for (int x = 0; x < str.size(); x++) { string num; count = 0; // Keeps count of even numbers // Loop checking for a sequence of number characters for (x; x < str.size() && str[x] >= '0' && str[x] <= '9'; x++) { // Converting current sequence of number character to an int num += str[x]; istringstream(num) >> temp; if (temp % 2 == 0) // Validate any even numbers { num = ""; count++; } } if (count >= 2) { return "true"; } } return "false"; }

22nd Nov 2022, 4:45 AM
$@G@®️
$@G@®️ - avatar
2 Respuestas
0
#include<iostream> using namespace std; int main() { int a,c,b; cout << "Enter a 1st Number : "; cin >> a ; cout << "Enter a 2nd Number : "; cin >> b ; c= a + b ; cout << "Addition of 1st and 2nd Number : " << c ; return 0; }
17th Mar 2023, 5:54 PM
Codrrrr
Codrrrr - avatar