[Solved] Is it possible to avoid integers,floats and special characters using try-except statement only?

That is reinventing the wheel, use str.isalpha You could use assert and AssertionError from string import ascii_letters value = None while True: try: value = input(“Give a value: “) assert all(c in ascii_letters for c in value) break except AssertionError: print(“Invalid input, try again”) print(“Valid input:”, value) Give a value: aa! Invalid input, try again … Read more

[Solved] Give standard input to program through files and take standard output to a file [closed]

You can use OS redirection operators java Test < inputFile > outputFile then this public class Test { public static void main(String[] args) throws IOException { for(int i; (i = System.in.read()) != -1;) { System.out.write((byte)i); } } } will copy from inputFile to outputFile 7 solved Give standard input to program through files and take … Read more

[Solved] File input output in c

the correct way is: int myreadfile(void) { FILE *fp; int i, n; unsigned char a[50]; if (!(fp=fopen(“x.exe”,”rb”))) return(0); while(n=fread(a,1,sizeof(a), fp)) { for (i=0; i<n; i++) printf(“%02x “,a[i]); printf(“\n”); } fclose(fp); return 1; } Note that the buffer is of type unsigned char. That is because a) you don’t know if the file is a complete … Read more

[Solved] how to ask for input again c++

int main() { string calculateagain = “yes”; do { //… Your Code cout << “Do you want to calculate again? (yes/no) ” cin >> calculateagain; } while(calculateagain != “no”); return 0; } Important things to note: This is not checked, so user input may be invalid, but the loop will run again. You need to … Read more

[Solved] How To Register user Form with all dynamic fields name in php

// Logic One Using For Loop <?php error_reporting(0); $con=mysql_connect(‘localhost’,’root’,”) or die(‘Not Connect’); mysql_select_db(‘multiple’,$con); if (isset($_POST[“submit”])){ $field_name = $_POST[‘values’]; $values = “”; for ($i = 0; $i < sizeof($field_name); $i++) { $values .= “(‘”.$field_name[$i].”‘)”; if ($i != sizeof($field_name) – 1) { $values .= “, “; } } $sql = mysql_query(“INSERT INTO php_test VALUES (” . $values.”)”); … Read more

[Solved] python: index of list1 equal to index of list2 [duplicate]

well what the comments said and change it like the following too : id = [1, 2, 3, 4, 5, 6] name = [‘sarah’, ‘john’, ‘mark’, ‘james’, ‘jack’] userid = int(input(‘enter user ID: ‘)) if userid in id: ind = id.index(userid) #notice this statement is inside the if and not outside print(name[ind]) else: print(“wrong id”) … Read more